Auto Logout when user leaves the application without doing logout action

后端 未结 3 1786
萌比男神i
萌比男神i 2021-01-28 20:43

Sometimes , an user leave an application without clicking on logout button, or do shutting down or hibernating of its Machine, pr even close all sessions (pages) which related t

3条回答
  •  有刺的猬
    2021-01-28 21:19

    You can do something like ,

    1. Set a session once user has logged in to your Site.

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

      this will keep track the activity from user

    2. On every page update this session to updated time(ie current time)

    3. Check for inactivity from user (here 30 minutes) and take necessary steps in unsetting the login credentials(before updating the session on top of every page)

      if($_SESSION['last_activity_recorded'] < time()+30*60){ session_unset(); session_destroy(); }

提交回复
热议问题