I have a user system and I use cookies to make them automatically logout after 1 hour of inactivity, but only if the client refresh the page it would update the database row. This is my code so far:
if(isset($_SESSION['username'])) {
$activeUser = $_SESSION['username'];
if(isset($_COOKIE['active'])) {
setcookie('active', $activeUser, time() +3600);
} else {
$makeOffline = $DB->query("UPDATE users SET user_loggedin = '0' WHERE user_id = '".$dbid."'");
header("location: ".$site_url."/logout.php");
}
}
What I'm asking now is if there's any way I could set user_loggedin
to 0 after 1 hour of inactivity without that the client have to refresh the page?