Welcome Guest, Not a member yet? Register   Sign In
Session->destroy doesn't work when using Flash-sessions.
#1

[eluser]Slowcheetah[/eluser]
Why ALL the sessions stay alive when i execute the following code?

ALL SESSIONS STAY ALIVE??
Code:
function signout() {
        // destroy all sessions (username and password)
        $this->session->sess_destroy();
        // set user message
        $this->session->set_flashdata('msg', 'Succesfully signed out.');
        // Redirect to signin page
        redirect('');
    }

If i don't set the flash message the code works perfect, and all sessions get destroyed. But cannot report to user

ALL SESSIONS DESTROY SUCCESFULLY
Code:
function signout() {
        // destroy all sessions (username and password)
        $this->session->sess_destroy();
        // Redirect to signin page
        redirect('');
    }
#2

[eluser]wabu[/eluser]
I think what's happening is that destroy sets an empty cookie but you're resetting it before it's sent (empty) along with the headers. That's why sess_destroy() needs to be called last.

Instead of trying to blow everything away, how about selectively clearing your user session data with unset_userdata()?
#3

[eluser]Slowcheetah[/eluser]
Thanks Wabu, works like a charm now.

The only problem now is that i have to remember to unset all the sessions manually when i sign-out. Is it possible to loop trough all session items and unset them??

CURRENT CODE
Code:
function signout() {
        // destroy all sessions
        $account_data = array(
            'account_id'=>'', 'username'=>'', 'password'=>'', 'email'=>''
        );
        $this->session->set_userdata($account_data);
        // set user message
        $this->session->set_flashdata('msg', 'Succesfully signed out.');
        // Redirect to signin page
        redirect('');
    }




Theme © iAndrew 2016 - Forum software by © MyBB