Jump to content

$_SESSION Termination Issues


dt_gry

Recommended Posts

Maybe you can use your database. You can add a field named login_time to your users table to store the date and time of user's login time. Everytime users login, update that field with the current date and time. And, everytime users navigate to the other page, compare the current date and time with that login_time field content. If the gap between them is bigger than the defined time, destroy the session.

 

And since session_destroy() only deletes the session data file, which will get recreated with any existing $_SESSION variables when the script ends, it is actually pointless to use session_destroy().

 

To automatically log someone out after they have been inactive for a time, you store their last active time (usually in a database table) and then you check for any last active times older then a limit you set. You can either check on each new page request and switch them to logged out at the start of a page request where too much time has gone past from their last active time or you can use a cron job/scheduled task to periodically switch anyone to being logged out who's last active time is older than your limit.

 

Also, a session is just a container. Don't waste a lot of time or lines of code trying to change how sessions work or when they end. Your application should use specific data to determine if and when someone is logged in/logged out.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.