Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User Inactivity Logout PHP

I want my users to be logged out automatically after X minutes of inactivity. I also want to have all sessions destroyed.

How can this be done? How can I check for inactivity then perform a function to log them out???

like image 782
user342391 Avatar asked Jun 18 '10 10:06

user342391


1 Answers

I tired Michiels approach and got no where. On investigation I saw that the if statement simply added the expiry period to the current time so the statement never fired.

This is my altered version:

set this when logging in user or loading a secure page:

 $_SESSION['expire'] = time()+1*60;

And use this to see if the expiry time is less than current time (i.e we're past the expiry limit):

if(time() > $_SESSION['expire']){
 $user -> logout();
}
like image 139
YsoL8 Avatar answered Oct 05 '22 05:10

YsoL8