Welcome Guest, Not a member yet? Register   Sign In
Redirect not working
#1

[eluser]Larry Wakeman[/eluser]
I am doing a logout by passing an additional segment 'logout' so I am going to /foo/bar/logout. In the logout code in the index function of my controller (I am using a single controller with a wild card route and letting the controller decide if the page exists and to display the correct content) so I put the following in:

Code:
if (stripos(uri_string(), 'logout') !== false)
{
    // perform a logout
    $this->cicms_login->logout();
    unset ($this->a_uri[(count($this->a_uri))]);
//    redirect(substr(uri_string(), 0, stripos(uri_string(), 'logout')-1));
    redirect('/foo/bar', 'refresh');
}
// display the page
As it is, the page is redirected to /foo/bar/foo/bar.
#2

[eluser]Larry Wakeman[/eluser]
I found the problem. Seems that it works with a full url as follows:

Code:
if (stripos(uri_string(), 'logout') !== false)
        {
            // perform a logout
            $this->cicms_login->logout();
            unset ($this->a_uri[(count($this->a_uri))]);
            redirect('http://'.$_SERVER['SERVER_NAME'].substr(uri_string(), 0, stripos(uri_string(), 'logout')-1));
        }
        // display the page
#3

[eluser]danmontgomery[/eluser]
Sounds like you have a bad value set in $config['base_url'].
#4

[eluser]Larry Wakeman[/eluser]
Yeah, that was the problem. Now if I change the config.php line:

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

to:

Code:
$config['base_protocol'] = 'http';

if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' && $config['base_protocol'] == 'http')
{
    $config['base_protocol'] .= 's';
}

$script_path = preg_replace('/(.+)index\.php$/', '$1', $_SERVER['SCRIPT_NAME']);
$config['base_url']    = $config['base_protocol']."://".$_SERVER["HTTP_HOST"].$script_path;

I will never have that problem again.




Theme © iAndrew 2016 - Forum software by © MyBB