Page 1 of 1

Termination of Session Variables

Posted: Fri Jan 05, 2007 8:38 pm
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.

Posted: Fri Jan 05, 2007 8:47 pm
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.

Posted: Fri Jan 05, 2007 8:50 pm
by jdhorton77
Ahh, ok, that makes since. Thanks.