Termination of Session Variables

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
User avatar
jdhorton77
Forum Commoner
Posts: 56
Joined: Tue Nov 07, 2006 3:29 pm
Location: Charlotte, NC

Termination of Session Variables

Post by jdhorton77 »

I've got Session Variables in my web site, but I'm curious about what happens when a user leaves the site. Do the variables destroy themselves after a period of time, or if the user leaves then comes back will the variables still be set. For instance in Java there is a garbage collector.

I'm also curious about the logic if a user is inactive for a while, how can I make it where it will destroy the variables, like sign out the user.

Thanks for sharing the knowledge.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Sessions are normally tracked by cookie, which (by default) are destroyed when the user closes the browser. On the server side, PHP does "collect the garbage" from time to time (PHP deletes old session files on a probability -- default is 1/100 chance of deletion for every page load).

You can keep track of idle time by setting time() to a session variable, and killing the session if that variable is older than N minutes.
User avatar
jdhorton77
Forum Commoner
Posts: 56
Joined: Tue Nov 07, 2006 3:29 pm
Location: Charlotte, NC

Post by jdhorton77 »

Ahh, ok, that makes since. Thanks.
Post Reply