Jump to content

Session timeout...


Aureole

Recommended Posts

I want sessions to time out and get destroyed if the user has been idle for more than x time...

 

I already have it so a timestamp is created and sent to the database per user every time they visit a page... so I have this timestamp available...

 

I know you use session_destroy() to destroy a user's session if they visit the link but is there anyway to have a script that say mass destroys sessions based on how old the timestamp is?

 

Searching Google yielded no (useful) results.

Link to comment
https://forums.phpfreaks.com/topic/72728-session-timeout/
Share on other sites

It is very easy. Use session_set_cookie_params(604800);    604800 is the number of seconds, so if you want the session to last an hour, then 60*60. This is the amount of time since last page load. I use this:

 

session_name("bookstoreID"); session_set_cookie_params(604800); session_start();

Link to comment
https://forums.phpfreaks.com/topic/72728-session-timeout/#findComment-366796
Share on other sites

No I don't want to specify how long the session lasts I just want it to time-out if the user has been inactive for x time...

 

Say they are inactive for an Hour then they come back and they are still signed in as the session still exists though they won't appear to be online as every half an hour a cron job checks for inactive members and sets the db field mem_online to 0...

 

This causes problems with my script when the db says they are offline but their session still exists so I need to destroy the session after x amount of inactivity...

 

Also I'm pretty damn 100% sure that session_start(); goes at the very top of the file...

Link to comment
https://forums.phpfreaks.com/topic/72728-session-timeout/#findComment-366810
Share on other sites

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.