Welcome Guest, Not a member yet? Register   Sign In
$this->session->sess_destroy() don't work
#1

[eluser]dsentker[/eluser]
Hey there, i've got a page (method) for "Logout" - that means, the session have to be destroyed. There are two entrys in the session:

Code:
$newdata = array(
    'user' => $this->acc['user'],
    'pass' => $this->acc['pass']
);
$this->session->set_userdata($newdata);

Now, here's the Logout-Page:

Code:
function logout() {
        $this->session->sess_destroy();
        redirect('adm');
    }

But the destroy process seems to fail:
Code:
function logout() {
        echo 'before: '.$this->session->userdata('user');
        $this->session->sess_destroy();
        echo 'after: '.$this->session->userdata('user');
        // redirect('adm');
    }

And the output is:
Quote:before: john-doe
after: john-doe

I thought, session destroying means "kill every info in the session"?
If i do that:

Code:
function logout() {
        $this->session->unset_userdata('user');
        $this->session->unset_userdata('pass');
        redirect('adm');
    }

- it works. Whats wrong with sess_destroy?
#2

[eluser]GSV Sleeper Service[/eluser]
This is due to the way CI uses 'sessions' - see, they call them 'sessions', but they're not, they're a kind of hybrid of sessions and cookies.

When you create a session in CodeIgniter it actually creates a cookie, and a cookie won't be updated until the next set of HTTP headers are sent. In your example you are destroying the 'session', and then requesting the data immediately after - there have been no new HTTP headers sent or received during the call to sess_destroy() and you requesting session->userdata('user')

This is why I always install the 'native sessions' library, which you can find in the CI wiki, once this is installed your sessions will operate as they should do (ie predictably and without the weird IE 7 glitches)
#3

[eluser]dsentker[/eluser]
Thank you. I don't like the CI-own "Sessions", too - but i thought they are "better" than PHP's regular Sessions. Now i am using the Native Session method as described in the wiki.

Thanks from Germany Smile




Theme © iAndrew 2016 - Forum software by © MyBB