Auto Logout when user leaves the application without doing logout action

后端 未结 3 1809
萌比男神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:34

    Try this:

    if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 600)) {
        session_unset();
        session_destroy();
    }
    $_SESSION['LAST_ACTIVITY'] = time();
    

    If $_SESSION['LAST_ACTIVITY'] > 600 no activity in last 600 seconds (10minutes) then destroy session.

提交回复
热议问题