Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.