简体   繁体   中英

base_url() returns wrong value

I am using Codeigniter 3.1.0 which latest now. I have set base_url in config.php as

$config['base_url'] = 'http://example.com/kp_clients/';

When I print base_url() . It is showing Server IP instead what I set.

http://173.x.xx.21/kp_clients/

Now what I am doing wrong here. Any idea?

I have autoloaded all required library

$autoload['helper'] = array('url');

and its working fine in local but stoppped working in live server

NOTE: base_url() function not working in codeigniter I have checked this. This is because not load url helper. I have clearly mentioned in my question that I have autoloaded the helper. Still its showing IP instead what I am setting

I got the issue. It was a old project & there were a directory name production in config folder. I was forgot about this directory & there were not set the base_url this is why its auto detecting server IP.

In fact my config.php was not active here. Rather production/config.php was working there. Now solved

Before using base_url() function load 'url' helper first in application/config/autoload.php

$autoload['helper'] = array('url');

Or, manually using $this->load->helper('url'); Now echo base_url(); gives the url what have loaded in $config['base_url'] config parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM