Ending sessions when the browser is closed

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
pistolfire99
Forum Commoner
Posts: 58
Joined: Thu May 23, 2002 3:18 pm

Ending sessions when the browser is closed

Post by pistolfire99 »

[Admin Edit: Moved from modcp.php?t=9726]

SBukoski:- Hey can you provide some kind of sample code. I am also in the same boat as the user who posted this message. How can I delete or force session to revalidate when a user doesnt log out, but closes the browser.
Another question I have is, how can I force the session to expire after certain time of inactivity, for ex:- something similar to yahoo mail or hotmail. If a user logs in, but is inactive for certain amount of time, and after that time, when the user clicks on one of the links, he has to login to the site, since his session has expired. Thank you for any help or sample code. Thank You
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

In this thread I show some sample code for using a cookie authenticator to protect a session. It includes the auto-expire requirements without requiring either PHP's sessions garbage collection or tracking of old sessions in a database. The script (the second version, linked near the end) probably needs some tweaking to work for you, but it should give you a decent starting point.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Please don't hijack other user's posts, I realise that if your question is similar it seems common sense to ask your question in the same thread but this can be confusing both for the original poster and for those trying to help when there are two conversations running in conjunction.

Mac
Post Reply