简体   繁体   中英

How to fix base_url() issue in CodeIgniter 3.1.0?

Suppose, I have a project inventory , written by CodeIgniter. The problem I face is:

In CodeIgniter 3.1.0 the value return by <?php echo base_url(); ?> <?php echo base_url(); ?> is http://[::1]/inventory/

but older version of CodeIgniter ( ie: 3.0.1 ) returns the full base path ( ie: http://localhost/inventory ).

Now, I want to return the full base path using base_url() in CodeIgniter 3.1.0 [ ie:: http://localhost/inventory instead of http://[::1]/inventory/ ]

Can anyone tell me how can I do that in CodeIgniter 3.1.0?

open your application/config directory where you will find config.php file. Now $config['base_url'] = ''; change this as following

$config['base_url'] = 'http://localhost/inventory/';

This is mandatory in Codeigniter 3.1.0

Please check your base url in application/config/config.php

change from

$config['base_url'] = 'something';

to

$config['base_url'] = (isset($_SERVER['HTTPS']) ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME'])) . '/';

$config['base_path'] = $_SERVER['DOCUMENT_ROOT'] . preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME'])) . '/';

No need to change anything after placing this .If ur using local or live host.

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