Sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpnitemare
Forum Newbie
Posts: 12
Joined: Sat Mar 28, 2009 1:14 pm

Sessions

Post 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
temidayo
Forum Contributor
Posts: 109
Joined: Fri May 23, 2008 6:17 am
Location: Nigeria

Re: Sessions

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