PHP Classes

logout

Recommend this page to a friend!

      Secure Session  >  All threads  >  logout  >  (Un) Subscribe thread alerts  
Subject:logout
Summary:code for logout
Messages:3
Author:ricky
Date:2006-02-13 17:45:51
Update:2006-03-24 18:10:25
 

  1. logout   Reply   Report abuse  
Picture of ricky ricky - 2006-02-13 17:45:51
Dude The code great ...
can u plz temme my how do i end this session....
in other words logout ...
i tried session_destroy()
and session_unset()

It gives me an error sayin object cannot be destroyed

  2. Re: logout   Reply   Report abuse  
Picture of Vagharshak Tozalakyan Vagharshak Tozalakyan - 2006-02-13 20:34:16 - In reply to message 1 from ricky
Try this:

foreach ($_SESSION as $k=>$v)
{
unset($_SESSION[$k]);
}
session_destroy();

  3. Re: logout   Reply   Report abuse  
Picture of Chris Smith Chris Smith - 2006-03-24 18:10:25 - In reply to message 1 from ricky
the correct way to logout:

// 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();

look in the phpmanual:
hu2.php.net/manual/en/function.sess ...