CodeIgniter Forums
Can't destroy session - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Can't destroy session (/showthread.php?tid=7715)

Pages: 1 2


Can't destroy session - El Forum - 04-20-2008

[eluser]steelaz[/eluser]
I simplified my logout function to:
Code:
function logout()
{
    $this->session->sess_destroy();
    log_message('error', 'mailcode: '. $this->session->userdata('mailcode'));
}

but I still get value from session in error log. Any suggestions how to troubleshoot this?


Can't destroy session - El Forum - 04-20-2008

[eluser]Pascal Kriete[/eluser]
sess_destroy changes the expiration time of the cookie to a negative time, so it disappears on the next refresh. Try reloading the page, you'll see it go away.


Can't destroy session - El Forum - 04-20-2008

[eluser]steelaz[/eluser]
Thanks, that did the trick


Can't destroy session - El Forum - 04-21-2008

[eluser]BD-CI-Programmer[/eluser]
I have same problem. I can not destroy session. Please help me..


Can't destroy session - El Forum - 04-21-2008

[eluser]Pascal Kriete[/eluser]
Nahid, did you try refreshing? Are you using the native CI session library?

If the answer to both is yes, could you post a reduced version of your code that reproduces the problem.


Can't destroy session - El Forum - 04-21-2008

[eluser]adamp1[/eluser]
Theres a simple fix to this,
Code:
$this->session->sess_destroy();
$this->session->sess_create();

It first resets the expire time, then creating a new session it overwrites the old one. So no need for a refresh.


Can't destroy session - El Forum - 04-23-2008

[eluser]Yunus Khan[/eluser]
Steelaz and Nahid please try with following code

Code:
unset($_SESSION['your session data']);
session_destroy();
redirect('as your required page', 'location');



Can't destroy session - El Forum - 04-23-2008

[eluser]webthink[/eluser]
Yunus, There's no indication that they're using native sessions.


Can't destroy session - El Forum - 04-23-2008

[eluser]Yunus Khan[/eluser]
Right. But steelaz wanted to know about this with logout function then I gave him this solution

Code:
function logout()
{
    unset($_SESSION['user_id']);
    unset($_SESSION['usertype']);
    session_destroy();
    redirect('admin', 'location');
}



Can't destroy session - El Forum - 04-23-2008

[eluser]webthink[/eluser]
I know but the code you provided will only work if he's using PHP's Native Sessions. There's no indication that he is. In fact there is every indication that he isn't.