Welcome Guest, Not a member yet? Register   Sign In
How to erform a logout?
#1

[eluser]Alhazred[/eluser]
For the login system I put some data into the session, on the restricted access pages I check if the data are inside the session.

My logout function is
$this->session->sess_destroy();
delete_cookie('crdsession');

Doing this the data which tells me if the user is logged should be deleted, but the users results to be logged even after the session_destroy(), his login data is still in the session (autoloaded).

I also use cookies and database to store the session's data, do I have to do something else to completely remove the session's data?
#2

[eluser]InsiteFX[/eluser]
You need to reset the user_data.
Code:
$this->session->userdata = array();
delete_cookie('crdsession');
$this->session->sess_destroy();
#3

[eluser]Alhazred[/eluser]
It's the same.

I've also tried to delete the db entry, the code now is
Code:
$query = "DELETE FROM crd_sessions WHERE session_id=?";
  
$this->db->query($query,$this->session->userdata('session_id'));
$this->session->userdata = array();
delete_cookie('crdsession');
$this->session->sess_destroy();
but if I print $this->session->all_userdata() I see all the data still there.
#4

[eluser]Alhazred[/eluser]
Damn, in one of the various change I deleted the call to the method, no matter what I put inside the model, it wasn't called XD

Sorry, now is ok.
#5

[eluser]InsiteFX[/eluser]
You do not need to delete the cookie ci will do that all you need is this
Code:
$this->session->userdata = array();
$this->session->sess_destroy();

// or try this
$data = array('empty' => 'empty');
$this->session->set_userdata($data);
$this->session->sess_destroy();




Theme © iAndrew 2016 - Forum software by © MyBB