phpsessiontimeoutlogoutuser-inactivity

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???


Solution

  • You could also do:

    $_SESSION['loginTime'] = time();
    

    On every page, and when the user is trying to navigate and he has been inactive for an twenty minutes you can log him out like this:

    if($_SESSION['loginTime'] < time()+20*60){ logout(); }