Jump to content

I want to expire the session after 30 mins of inactivity, but online all the solutions i found have it set that it expires even if you click/move around the site. I want it that if you click anywhere on the site it will start counting down from 30 minutes again. Any advice?

Link to comment
https://linustechtips.com/topic/1017201-php-expire-session/
Share on other sites

Link to post
Share on other sites

So the problem your having is your not updating the expiration to now+30 mins everytime they do something.

 

PHP runs on the server and not on the user's browser - so it will only know they have done something when it causes the page to load by refreshing or clicking on a link. 
In your code where you check if the session is expired - if it is not you need to set the expiration time to now+30 mins or whatever. 

This does not handle "moving the mouse". Since this is based on server requests PHP is not going to know what the user is doing on the browser like typing or moving the mouse or scrolling. That takes something client-side like javascript. It's a bit more complicated too - I would suggest having a pop up (modal or confirm dialog) saying "hey your about to be logged out! click ok to stay logged in!" and then if they click ok reload the page or something. 

To do it without a page reload you will need to use ajax calls to tell the server your user is still there. (more advanced)

 

Link to comment
https://linustechtips.com/topic/1017201-php-expire-session/#findComment-12155154
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×