logout feature in code igniter

2019-04-14 19:01发布

问题:

I started using codeigniter for my project. I have user authentication system for my website. I have seen the videos from nettuts for the login information. I am confused why the logout is not working properly.

I have the following logout function in my login controller.

function logout() {
        $this->session->sess_destroy();
        redirect('main');
    }

If I click on the logout button I am redirecting the user to the main page. But after redirecting the user to the main page, if click on the back button on the browser I will see the logoff and my name on the top of the page. I need some help on where I am going wrong or is there any important piece of code I am missing in my controller

Thanks in advance

EDIT

I think I found the solution. I should append the following code into the appropriate controller

$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache"); 

回答1:

I think this is a browser cache issue. If you click back you are actually seeing the cached page, the way it was when you were logged in.

Try and hit F5 when just after going back to the before logout page. It should now show that you are logged out.



回答2:

Adding header to my main constructor solved my problem with IE7:

$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache");