dhimok Posted April 8, 2007 Share Posted April 8, 2007 Hello everyone! How can I expire login if it has been inactive for some time? I am using sessions as login. Thanks in advance Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 im having the same sort of thing...... http://www.phpfreaks.com/forums/index.php/topic,135061.0.html but what i do is use cookies and store the login length. ( in and the out) so that if somone hasnt logged out within x minutes ,then it defult loggs them out, and stors login length as only 5 minutes, not 20 minutes eg. this "entices" the user to logout correctly gd luck Quote Link to comment Share on other sites More sharing options...
per1os Posted April 8, 2007 Share Posted April 8, 2007 <?php session_start(); // note you must set $_SESSION['time'] on your own when the user logins as something like // time()+3600; expires in one hour if ($_SESSION['time'] > time()) session_destroy(); ?> Quote Link to comment Share on other sites More sharing options...
dhimok Posted April 8, 2007 Author Share Posted April 8, 2007 I want to log them out only if page has been inactive lets say for 20 mins. I do not want to set an amount of time and then expire in case they are doing something with the page Quote Link to comment Share on other sites More sharing options...
per1os Posted April 8, 2007 Share Posted April 8, 2007 You would either need to have the session data stored in a db with lastactivity as a time field and use a cron job or setup some code to run at the top of a page anytime it is called and check the database session lastactivity and if it is past 20 minutes delete that hash from the DB so the next time the person loads the page check to see if the session still exists if not prompt them to login again. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 well thats where it gets complicated. ill be doing this sson with my site, but at the begining of every page you write a page request log to the database. fields = request_id, user_id, time, page_name what you do is search the records for User_Id = $User_Id, and time. find the most recent request ( via time ) and say if it was more than 20 minutes ago, then theyre inactive, and do your logout thing. its requires almost a new start. or at least a new version please note that i may be completely wrong, and there may be a really easy fool proof way of doing it that i dont know if....... either way, good luck. ill folliw this thred becauase ill be using it soon. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 yes good point, frost110 is must simpler. go with that!!!!! Quote Link to comment Share on other sites More sharing options...
dhimok Posted April 8, 2007 Author Share Posted April 8, 2007 Ok, thanks, I will try that and see how it goes, I ll let now 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.