I have an almost working registration system on my website, the only part missing is the logout function. It starts the session but doesn't seem to destroy it, therefore, the previous session is always active. Am I destroying the session correctly or am I doing something entirely wrong?
At first, I just tried setting the user data and then unsetting them one by one before destroying the session, that didn't work. So now I set the user data with plain strings before destroying them, again, doesn't seem to work.
the logout link looks like this:
<a href="http://localhost/dir/dir1/dir2/index.php/Controller/logout">logout</a>
In my controller I have this:
public function logout() {
$this->load->helper('url');
$this->load->library('session');
$session_data = array(
'data' => 'data',
'data' => 'data',
'data' => 'data',
'data' => 'data',
'data' => 'data',
'data' => 'data',
'data' => 'data',
'data' => 'data',
'data' => 'data',
'data' => 'data',
'data' => 'data',
'data' => 'data',
'data' => 'data',
'data' => 'data'
);
$this->session->set_userdata($session_data);
$this->session->unset_userdata('data');
$this->session->unset_userdata('data');
$this->session->unset_userdata('data');
$this->session->unset_userdata('data');
$this->session->unset_userdata('data');
$this->session->unset_userdata('data');
$this->session->unset_userdata('data');
$this->session->unset_userdata('data');
$this->session->unset_userdata('data');
$this->session->unset_userdata('data');
$this->session->unset_userdata('data');
$this->session->unset_userdata('data');
$this->session->unset_userdata('data');
$this->session->unset_userdata('data');
$this->session->sess_destroy();
redirect('http://localhost/dir/dir1/dir2/index.php/Controller/loginview', 'refresh');
}
I expect the session to be destroyed before it redirects(which it does), yet when I type in the new login credentials it still shows the ones from the previous session, it should instead show the new ones.