Chaori Posted December 2, 2008 Share Posted December 2, 2008 I'm making a text based MMO, just wondering if there's any way to have a player's session expire after 10 minutes of inactivity? Because my login script sets $online to 1, and my logout sets $online to 0, and i want to make it so if they are inactive for 10 minutes, it sets $online to 0 and it ends their session so the next time they try and move it redirects them to the login screen. Can anyone help me do this? Quote Link to comment https://forums.phpfreaks.com/topic/135139-session-timers/ Share on other sites More sharing options...
VBAssassin Posted December 2, 2008 Share Posted December 2, 2008 Sure, open up the php.ini file and put this: session.gc_maxlifetime= 600 if you can't do that, put this in a htaccess file instead, or use ini_set() at run time. Kind regards, Scott Quote Link to comment https://forums.phpfreaks.com/topic/135139-session-timers/#findComment-703856 Share on other sites More sharing options...
jake2891 Posted December 2, 2008 Share Posted December 2, 2008 http://uk3.php.net/manual/en/function.session-cache-expire.php Quote Link to comment https://forums.phpfreaks.com/topic/135139-session-timers/#findComment-703858 Share on other sites More sharing options...
Chaori Posted December 2, 2008 Author Share Posted December 2, 2008 Unfortunately, it isn't my server so I don't have access to those files. However, I'm sticking session_cache_expire(10); at the start of every page, so that it refreshes when you do something. Now I need to know how to make it set $online to 0 once the session expires. Quote Link to comment https://forums.phpfreaks.com/topic/135139-session-timers/#findComment-703865 Share on other sites More sharing options...
PFMaBiSmAd Posted December 2, 2008 Share Posted December 2, 2008 Neither of those suggestions will accomplish what you ask. Session garbage collection runs randomly, unless you also change the parameters to cause it to run on every session_start(), which on a busy server and with a lot of session data files will slow down your script. I'm guessing you don't want your script to run any slower than necessary? You must also set the session save path to be to a private folder within your account's space so that the settings only affect your session data files. The session cache expire setting only affects how long a page using sessions is cached in the browser before the browser will request that page from the server or use it out of the cache. To get your application to have a specific time limit, you must store the last access time on each page visit and then simply check on each page visit if that time is farther in the past then the limit you want. If it is, you redirect to or display the login page. If it is not, you update the stored time with the current time and execute the normal code on the page. Quote Link to comment https://forums.phpfreaks.com/topic/135139-session-timers/#findComment-703893 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.