Welcome Guest, Not a member yet? Register   Sign In
$this->session->sess_destroy(); doesn't destroy all session
#1

[eluser]Alpha[/eluser]
hi, i have $this->session->set_userdata(‘user_id’, ‘ID1’);

then i want to logout and used $this->session->sess_destroy();
but to my surprise $this->session->set_userdata(‘user_id’, ‘ID1’) still exist

based on this http://ellislab.com/codeigniter/user-gui...sions.html it should destroy all
#2

[eluser]WanWizard[/eluser]
Sigh.

As I said (and this is the third time), sess_destroy() doesn't erase the user_data array.

I know it says that. But it doesn't. And it never did.
#3

[eluser]Alpha[/eluser]
Smile i want to report this as a bug, my session database has been spammed with session_id due to my troubleshooting of login-logout. ok that's the last.

tnx a lot Smile
#4

[eluser]tinawina[/eluser]
Ok - I did read the manual, and I started out using $this->session->sess_destroy() and that didn't work so I came here and found this post. Tried unset($this->session->userdata) but that didn't kill my session either. What I ended up doing is killing each session variable individually:

$this->session->unset_userdata('username');
$this->session->unset_userdata('userid');
$this->session->unset_userdata('useremail');
...

To do this quickly you could loop through the session array, turning each one off as you loop.

This was the only way I found to kill my session.
#5

[eluser]WanWizard[/eluser]
sess_destroy() does destroy the session, but it doesn't reset already loaded data.

Ideally, after you destroy the session, you should do a redirect and not continue.
#6

[eluser]tinawina[/eluser]
Right - I do a redirect with a refresh and all works fine. I'll try sess_destroy(). Thanks.
#7

[eluser]InsiteFX[/eluser]
Code:
$this->session->userdata = array();
$this->session->sess_destroy();
redirect('home', 'refresh');
#8

[eluser]tinawina[/eluser]
InsiteFX - like!
#9

[eluser]skunkbad[/eluser]
If you really want to delete the entire session, and not leave anything behind, you can use php's setcookie() function.

Code:
<?php
setcookie( config_item('sess_cookie_name'), '', time() - 3600 );

This would delete the entire session cookie. Remember, you are not limited to CodeIgniter when using CodeIgniter, it's just a framework.

Actually, if you already use the cookie helper, you can just use:

Code:
delete_cookie( config_item('sess_cookie_name') );




Theme © iAndrew 2016 - Forum software by © MyBB