Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/135139-session-timers/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/135139-session-timers/#findComment-703865
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/135139-session-timers/#findComment-703893
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.