Pure, server-side PHP. Every time a user submits a form, I update a \'last activity\' time in the database.
I want to make a periodic check and force logout inactiv
With each login, you need to keep track of the Session Start Time, which can be done like this:
$_SESSION['SessionStartTime'] = time();
With each user request to perform any operation, you need to run this script to monitor inactivity.
<?php
session_start();
$TimeOutMinutes = 15; // This is your TimeOut period in minutes
$LogOff_URL = "login.php"; // If timed out, it will be redirected to this page
$TimeOutSeconds = $TimeOutMinutes * 60; // TimeOut in Seconds
if (isset($_SESSION['SessionStartTime'])) {
$InActiveTime = time() - $_SESSION['SessionStartTime'];
if ($InActiveTime >= $TimeOutSeconds) {
session_destroy();
header("Location: $LogOff_URL");
}
}
$_SESSION['SessionStartTime'] = time();
?>