PHP logout with Codeigniter

Asked

Viewed 435 times

4

I am having a problem in logout of my system, it until it is logging out correctly and destroying the sessions, but if the user clicks the back button of the browser it goes back to the previous page of the system where all the data is displayed again. The code is like this:

public function logout()
{
    $this->session->sess_destroy(); //destroi a sessao
    redirect('/'); // redireciona para a raiz do sistema(pagina de login)
}

Even destroying the session, he can access the previous page of the system, the session checks within the program are correct, because if he clicks on a link and goes to another module he will be expelled from the system.

Can anyone help me?? Thank you :)

  • I think a good practice is to analyze the Sesssions before rendering the content. If the session is empty, redirect to the login.

2 answers

3

There is a time that I don’t work with Codeigniter, but the solution below will work with any other framework (or even in pure PHP).

Considering that you have destroyed the session, to ensure that the previous session is not accessed (either by some framework bug or any other error), you can simply regenerate the id, so that the previous reference is lost.

In that case, do so:

public function logout()
{
    $this->session->sess_destroy();

    $this->session->regenerate_id();

    redirect('/');
}

Updating

It has been informed that regenerate_id didn’t work. So, you can use $this->session->sess_update().

  • Did not work, Codeigniter does not have regenerate_id function()

  • If the update doesn’t work, I remove the post.

0

Only

 public function sair(){
    $this->session->sess_destroy();
    
    redirect('view aonde quer voltar');
  }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.