I want a user to be automatically logged out after 30 minutes if he hasn't been active.
I've tried the following code :
Index.php :
<?
if ((time() - $_SESSION['last_activity']) > 1800) // 30* 60 = 1800
{
header("Location: logout.php");
}
?>
login.php:
<?
$_SESSION['unm'] = $row['u_unm'];
$_SESSION['uid'] = $row['u_pwd'];
$_SESSION['status'] = true;
$_SESSION['last_activity'] = time();
?>
My problem is I don't understand how this code is keeping track of user activity?
The problem I am facing is determining whether the user is active or not. But I want the user only to be logged out if he is not doing anything.
Can anybody tell me how to keep track of that? Thanks.