它应该在 20 分钟不活动后注销,但它会在 3-4 秒后注销,我不知道我哪里出错了。我知道还有其他问题,但我已经看过但找不到解决方法。
<?php
session_start();
if ((isset($_SESSION['Username']) && $_SESSION['Username'] != "") || (isset($_SESSION['uID']) && $_SESSION['uID'] != "") || (isset($_SESSION['Password']) && $_SESSION['Password'] != "")) {
$selectUsers = $PDO->query("SELECT * FROM `users` WHERE uID='{$_SESSION['uID']}'");
$getRow = $selectUsers->fetch(PDO::FETCH_ASSOC);
if ($getRow['lasthit'] == time()+20*60) {
session_destroy();
session_unset();
$PDO->query("UPDATE `users` SET online=0 WHERE uID='{$_SESSION['uID']}'");
header("Refresh:3; URL=login.php");
} else {
$updateLastHit = $PDO->query("UPDATE `users` SET lasthit=NOW() WHERE uID='{$_SESSION['uID']}'");
}
} else {
header("Refresh:3; URL=login.php");
echo '<p class="error">You need to login, you are being redirected to login page.</p>';
endPage();
}
?>