Welcome Guest, Not a member yet? Register   Sign In
how to destroy a session and immediately create a new one?
#5

[eluser]Narkboy[/eluser]
I have / had a similar issue with "delayed destruction". Basically, when logging a user out, I called sess_destroy and then loaded a view that said "you logged out". The view contains a login form is the user is logged out, or the user data if they are logged in.

What was happening was that the debug message printing all session userdata indicated that the user had logged out, but the login form was not displayed - it still thought the user was logged in. A refresh made the view work correctly.

Solution: in the login controller, the logout function does this:

Code:
function logout()
{
    if($this->session->userdata('user_name'))
    {
        $this->session->unset_userdata('user_name');
        $this->login_model->do_logout();

        redirect('login/logout/','location');
    }
// Now display the view saying they logged out..
}

Basically, the function checks for the 'user_name' is the session; if it finds it, it deletes it, destroys the session and call itself again. Rinse and repeat. Logging shows that this happens only once, but I don't know why.

I assume that the sess_destroy function actually gets invoked by the destructor and therefore requires the script to run start to finish. By calling a view within the same script as the logout functions, I am effectively acting before the destructor can destroy the session. Just a guess..

Try something similar and see how you get on.

Smile

// Edit - just realise that the code is the dev version before I tidied it up. The logout and user_data delete will both be handled by the login_model. Don't flame me for poor MCV work kthxbye! Big Grin


Messages In This Thread
how to destroy a session and immediately create a new one? - by El Forum - 04-17-2010, 10:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB