Shimul
Shimul

Reputation: 469

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(); ?> is http://[::1]/inventory/

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

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

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

Upvotes: 1

Views: 1336

Answers (2)

dhruv jadia
dhruv jadia

Reputation: 1680

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 u r using local or live host.

Upvotes: 1

Rejoanul Alam
Rejoanul Alam

Reputation: 5398

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

Upvotes: 1

Related Questions