Welcome Guest, Not a member yet? Register   Sign In
CI 2.x->3.x Redirect?
#1

I'm upgrading from CI 2.x to CI 3.x. I have this line in my default controller for users who aren't logged in:

PHP Code:
redirect('/auth/login/'); 

This used to redirect to:

http://localhost/index.php/auth/login/

...but now is redirecting to:

http://localhost/localhost/index.php/auth/login/

Where's the right place for me to begin looking for the way to correct this?
Reply
#2

In config.php make sure that $config['base_url'] is set. You used to be able to get away with not setting it. Not so with CI 3.x.
Reply
#3

(This post was last modified: 11-11-2016, 04:08 PM by VikRubenfeld.)

Update: After the redirect, in CodeIgniter.php, looking in $_SERVER[], I see:

Code:
[REDIRECT URL] = "/localhost/index.php/auth/login/"

That is as expected. But I also see:

Code:
[PHP_SELF] = "/index.php/localhost/index.php/auth/login/"
[PATH_TRANSLATED] = "redirect:/index.php/localhost/index.php/auth/login//index.php/auth/login/"

Does that shed any light?
Reply
#4

(This post was last modified: 11-11-2016, 04:23 PM by VikRubenfeld.)

Update: Looks like it's happening in site_url($uri)... investigating...
Reply
#5

(11-11-2016, 04:01 PM)dave friend Wrote: In config.php make sure that $config['base_url'] is set. You used to be able to get away with not setting it. Not so with CI 3.x.

I didn't see this before-- checking now...
Reply
#6

I access my development site using 'localhost', e.g. 'localhost/auth/login'. I have $config['base_url'] set to 'localhost'. Is that correct?
Reply
#7

(This post was last modified: 11-11-2016, 04:34 PM by VikRubenfeld.)

Tracing through the redirect code, I get to this at the bottom of function redirect():

PHP Code:
header('Location: '.$uriTRUE$code); 

$uri = "localhost/index.php/auth/login/"

$code = 307

But, it appears to redirect to:

http://localhost/localhost/index.php/auth/login/

Does this provide a clue?
Reply
#8

(This post was last modified: 11-11-2016, 06:41 PM by VikRubenfeld.)

Tracking it down!

redirect('/auth/login/');

...is updated by function redirect() to:

$uri = "localhost/index.php/auth/login/"

...which looks good. The redirect takes place and CodeIgniter restarts for the new URL.  Then in CodeIgniter.php, line 402, the following line executes:

if (empty($class) OR ! file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php'))

APPPATH.'controllers/'.$RTR->directory.$class.'.php' evaluates to :

"/Applications/myApp/application/controllers/Localhost.php"

...even though localhost is not a controller. This results in a 404 error.

It appears that on the call to:

Code:
    public function set_class($class)
    {
        $this->class = str_replace(array('/', '.'), '', $class);
    }

...in Router.php, $class has been set to localhost, based on the URL "localhost/index.php/auth/login/".

This does not seem to be the expected behavior. What am I missing?
Reply
#9

In application/config.config.php what is $config['base_url'] = ?????

It should probably be

PHP Code:
$config['base_url'] = 'http://localhost/'
Reply
#10

That fixed it. I just had:

$config['base_url'] = 'localhost/';

Thank you very much!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB