Aureole Posted October 11, 2007 Share Posted October 11, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/72728-session-timeout/ Share on other sites More sharing options...
sKunKbad Posted October 11, 2007 Share Posted October 11, 2007 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(); Quote Link to comment https://forums.phpfreaks.com/topic/72728-session-timeout/#findComment-366796 Share on other sites More sharing options...
Aureole Posted October 11, 2007 Author Share Posted October 11, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/72728-session-timeout/#findComment-366810 Share on other sites More sharing options...
sKunKbad Posted October 11, 2007 Share Posted October 11, 2007 Also I'm pretty damn 100% sure that session_start(); goes at the very top of the file... I've got about 250 pages that use that code without any errors. Quote Link to comment https://forums.phpfreaks.com/topic/72728-session-timeout/#findComment-366818 Share on other sites More sharing options...
Aureole Posted October 11, 2007 Author Share Posted October 11, 2007 Alright. Quote Link to comment https://forums.phpfreaks.com/topic/72728-session-timeout/#findComment-366820 Share on other sites More sharing options...
Aureole Posted October 11, 2007 Author Share Posted October 11, 2007 Bump. Quote Link to comment https://forums.phpfreaks.com/topic/72728-session-timeout/#findComment-367165 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.