I was messing with sessions and noticed that if I just closed my browser, it didn’t destroy them.
If I clicked on Log out, it destroyed that session.
I have a /tmp directory I put my sessions into. The reason I started pondering sessions was when I was tinkering with users and saw the session numbers were being held over from one user to the next.
I went to /tmp and saw a whole listing of old sessions that seemed to be contaminating the newer ones.
This is what I have been using:
// Unset all of the session variables.
$_SESSION = array();
// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (isset($_COOKIE[session_name()])) {
setcookie(
session_name(),
'',
time()-42000,
'/'
);
}
// Finally, destroy the session.
session_destroy();