Welcome Guest, Not a member yet? Register   Sign In
session destroy, not destroying session?
#1

[eluser]x_dde_x[/eluser]
I know that I'm doing something wrong. I'm trying to kill an entire session, and effectively log a user out.

However, my logout script doesn't seem to be working
Code:
function logout()
        {        
                $this->session->sess_destroy();  
            echo $this->session->userdata('session_id');
        }

If the session is destroyed, shouldn't the session_id echo be NULL?

(for the record, this is how I'm setting the session information:
Code:
$userdata=array('session_id'=> md5($username), 'userid'=> $username);
              $this->session->set_userdata($userdata);
#2

[eluser]TheFuzzy0ne[/eluser]
No. All it does is kills the users cookie, but the userdata will remain within the session class until the end of the current request. The session will be reinitialised on the next request, and there will be no userdata available. Basically, all it does is severs the link between the user and the server session, but the data still remains until the end of the request.

If it's that much of an issue, you can do this:
Code:
$this->session->userdata = array();
#3

[eluser]TheFuzzy0ne[/eluser]
...Or you can extend and override the session class with something like this:

./system/application/libraries/MY_Session.php
Code:
<?php

class MY_Session extends CI_Session {
    
    function sess_destroy()
    {
        parent::sess_destroy();
        $this->userdata = array();
    }
    
}

// End of file: MY_Session.php
// Location: ./system/application/libraries/MY_Session.php
The above code is untested.




Theme © iAndrew 2016 - Forum software by © MyBB