libertyct Posted August 27, 2008 Share Posted August 27, 2008 i need to setup functionality that automatically logs out a user after a certain amount of time of inactivity. how would you go about this task? I am not asking for code, just ideas, i was thinking of using a javascript timer but im not sure if that would work well on a page that uses Ajax since i wont be able to detect any page re-loads. thnx! Quote Link to comment Share on other sites More sharing options...
trq Posted August 27, 2008 Share Posted August 27, 2008 i need to setup functionality that automatically logs out a user after a certain amount of time of inactivity. PHP does this automatically, I think the default value is 20 mins. Take a look in your php.ini at the session settings. Quote Link to comment Share on other sites More sharing options...
revraz Posted August 27, 2008 Share Posted August 27, 2008 The PHP.INI holds the Garbage Collector (GC) settings, which determines how often it runs and what sessions get deleted. This may or may not be the result you are looking for. Quote Link to comment Share on other sites More sharing options...
libertyct Posted August 27, 2008 Author Share Posted August 27, 2008 well i am looking for a way to automatically redirect to something like a error page eg after 5 mins of inactivity -> logout user -> show inactivity message! Quote Link to comment Share on other sites More sharing options...
discomatt Posted August 27, 2008 Share Posted August 27, 2008 Use sessions, and adjust the session timings http://bytes.com/forum/thread2477.html might help From what I've read though, you're much better off creating or using a custom session handler ( database-driven is usually best ) for more accurate control. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted August 27, 2008 Share Posted August 27, 2008 If you use cookies, you can include a script to be ran for each page. Maybe like in the header of each page? Or if you have a php file that is ran on every page, you can put it there. In that script, you can create a cookie with the time the user last refreshed in UTC format. Then upon every refresh, check if the cookie is set, and if it is, subtract the current time from the cookie time and if that is greater than a certain amount, remove all the cookies for that site. Otherwise, change the cookie time to the current time. Quote Link to comment Share on other sites More sharing options...
libertyct Posted August 27, 2008 Author Share Posted August 27, 2008 I have done adjustments to the session lifetime before, so if a user returned to a page and thier session had died out i could redirect them to a logout page, but i want to have this automated, such that the user gets booted automatically without the user refreshing the page. maybe this is something possible on ASP.NET and not PHP? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted August 27, 2008 Share Posted August 27, 2008 I have done adjustments to the session lifetime before, so if a user returned to a page and thier session had died out i could redirect them to a logout page, but i want to have this automated, such that the user gets booted automatically without the user refreshing the page. maybe this is something possible on ASP.NET and not PHP? For that, either use JavaScript timer or HTML META tag with the given amount of seconds specified. So 20 minutes is 20 minutes * 60 seconds = 1200 seconds. Redirect the user to the logout php page when the timer expires and in the logout.php, redirect the user back to the homepage after deleting their sessions. You can use PHP to generate the META HTML if you want. Quote Link to comment Share on other sites More sharing options...
discomatt Posted August 27, 2008 Share Posted August 27, 2008 I have done adjustments to the session lifetime before, so if a user returned to a page and thier session had died out i could redirect them to a logout page, but i want to have this automated, such that the user gets booted automatically without the user refreshing the page. maybe this is something possible on ASP.NET and not PHP? Yes, javascript redirect or meta refresh. Use this as a secondary for sure though, as both are a one-click disable in most modern browsers. Quote Link to comment 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.