Page 1 of 1

Sessions

Posted: Mon Apr 06, 2009 3:32 am
by phpnitemare
Hi

I have created a session that is running on the web-pages fine. However, the session does not seem to expire when I close the browser. Is there a way to end the session/reset the session variables on a mouse click e.g. clear basket that resets pointers and items in an array?

Thanks

Re: Sessions

Posted: Mon Apr 06, 2009 2:35 pm
by temidayo
Here is a code you can use on mouse click. It is straight from php manual

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