Page 1 of 1
unsetting sessions [SOLVED]
Posted: Tue Nov 08, 2005 4:22 pm
by s.dot
How do i unset a session... ie the user has clicked a logout link.
With cookies I would set the cookie to a past time value
I read about unset() in the php manual, but it says do NOT use unset($_SESSION);
Posted: Tue Nov 08, 2005 4:26 pm
by Luke
session_destroy() and you still have to unset the cookie I think.
Posted: Tue Nov 08, 2005 4:28 pm
by s.dot
apparently its a combination, as shown when I looked up session_destroy... thanks
for those who didn't know
Code: Select all
<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();
// 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();
?>