PHP Logout with CodeIgniter

4

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

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

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

Can anyone help me ?? Thanks:)

    
asked by anonymous 03.02.2016 / 12:35

2 answers

3

I have a time that I do not mess with Codeigniter, but the solution below will work with any other framework (or even pure PHP).

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

In this case, do so:

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

    $this->session->regenerate_id();

    redirect('/');
}

Update

It was reported that regenerate_id did not work. So you can use $this->session->sess_update() .

    
03.02.2016 / 12:49
0

Only

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