I found it is unusual with the latest stable version of CI (3.03),
I tried echo base_url() and it returns some unusual thing,
**Note: ** I have loaded the URL helper .
The following code
$this->load->helper('url');
echo base_url();
returns http://127.0.0.1/ (I have used http://localhost/ to interpret the application) in Firefox.
And:
http://::1/ (Same I have used http://localhost/ ) in Chrome ?
Help me guys in fixing this.
Please remove base_url form the config file if you set there,
$config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/";
In your config, use define. like below:
define('base_url', 'http://localhost/your_project name/');
And then try
echo base_url() ;
Make sure you have set a base url
$config['base_url'] = 'http://localhost/project/';
Some times for me that is issue.
In older versions of CI you use to be able to leave that blank but.
Now it is recommended that you do not leave that base_url blank.
And I would auto load the url helper as it is the most common one.
Related
I am using XAMPP, MySQL and CodeIgniter.
I already included,
$autoload['helper'] = array('url');
in autoload.php.
<?php echo base_url(); ?>
returns http://::1/mysite/ instead of http://localhost/mysite/.
Can anyone help me with this issue?
You need to make sure you have set your base_url in. Most likely because you left it blank. This is a common thing that people do not know about or forget to do.
application > config > config.php
$config['base_url'] = 'http://localhost/mysite/';
One of the issues when you try to submit form with out base url not set is will not go to correct url, when you try to submit a form so that why in codeigniter 3 all ways best to set your base_url even though not a requirement.
Also here are some htaccess for codeigniter xampp & wamp
Htaccess For Codeigniter
I'm using site_url function on my project but there is something weird. It gets my Ipv6.
For example, I'm echoing site_url() and this is what I get:
http://fe40::8a43:dfff:feb3:ecff/project/
Actually I did not try anything to solve it 'cause I couldn't find anything about this problem on web. I can't use base_url, I have to use site_url. Please don't suggest things like this.
Thanks in advance.
Taken from the comment:
Try assigning your
$config['base_url'] = '';
to a specific address.
i have developed a php application which is running perfect on local server. when i deployed the application on web server the links are not working
1) my site is "abc.myapplication.com" (abc is subdomain)
i defined following variable in config file
define('ROOT_PATH', $_SERVER['DOCUMENT_ROOT']);
ROOT_PATH variable shows /home/punjabfo/public_html/abc (which is perfect)
for link i used following code
Add Record
link should go to "abc.myapplication.com/addrecord.php" but link go to
"abc.myapplication.com/home/punjabfo/public_html/abcaddrecord.php"
i tried a lot but could not fin the issue. please help. thanks
What is wrong with Keeping It Simple
Add Record
Let the server do all the work, as it gets it right and you do less messing around.
Try
define('ROOT_PATH', $_SERVER['HTTP_HOST']);
Just use
Add Record
You can try -
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo 'http://'.parse_url($url, PHP_URL_HOST) . '/';
Your issue is "$_SERVER['DOCUMENT_ROOT']". $_SERVER['DOCUMENT_ROOT'] stands for the root directory on the server (dir-path). What you need, is the URL and not the file-system-path.
Take a look on
<?php
echo "<pre>";
var_dump($_SERVER);
echo "</pre>";
?>
Why not to do
Add Record
Of course you do not need ROOT_PATH in the URL. What you do is returning full path of the file, instead of link. And btw, full path is incorrect itself, as you forgot slash before addrecord.php.
i notice that when i run a zend framework app from a server, there are alot of side effects. main issue is where i use urls like
/auth/login
i need to use
$this->baseUrl('/auth/login');
thats simple to fix. but when i use
$request->getRequestUri()
for use in redirects. eg after login, i want to redirect the user back to the prev page, it goes to the wrong place. eg. my app root is "http://localhost/app1", $request->getRequestUri() will give /app1. when i try to redirect back, it will goto http://localhost/app1/app1. btw, i am using Zend Server + IIS7 and my app is configured to run from the url stated above. maybe i shld be going to "/" instead. how can i resolve this?
update
this is in my Zend_Form class
// (Zend_Form) Login.php init()
$req = Zend_Controller_Front::getInstance()->getRequest();
$returnUrl = $req->getParam('returnUrl', $req->getRequestUri());
$this->addElement('hidden', 'returnUrl', array(
'value' => $returnUrl
));
// AuthController after login
$returnUrl = urldecode($form->getElement('returnUrl')->getValue());
if (!empty($returnUrl)) {
$this->_helper->getHelper('Redirector')->setGotoUrl($returnUrl);
}
Based on you update:
Its the prependBase-Option in the Redirector what you are looking for:
prependBase: boolean flag indicating whether or not to prepend the base URL when a relative URL is provided
So your fix is:
$this->_helper->getHelper('Redirector')->setGotoUrl($returnUrl, array('prependBase' => false));
If you are using Zend_Application you can use this in your application.ini, and wont need to specify anything else.
resources.frontController.baseUrl = "/your/public/path/"
I have solved this problem with help of Apache configs. In file \usr\local\apache\conf\vhosts.conf find a block with your site and change ways and public folder.
I am having a bit of a problem. I am duplicating my website to a test environment on a new server with a new domain.
I have it working fine with the database etc but here is my error.
On the live site if I click suppliers it goes to the page fine If I click it on the test environment it does not work.
These are two links
http://wvtest.co.uk/
http://theweddingvine.com/
The code to create the link is as follows:
<?php
echo anchor('search', 'Suppliers');
?>
The file and the folders are the same. Is there something in codeigniter which can direct the link ?
Modify application/config/config.php and set:
$config['base_url'] = "http://{$_SERVER['HTTP_HOST']}/";
That will make your links work on either server.
have you specified the correct base_path for your testing server in application/config/config.php file?
Check that please, this is the case mostly in such problems.
You could change your base_url to
$config['base_url'] = 'http://wvtest.co.uk/';
or
$config['base_url'] = '/';