如果用户没有在网站上进行任何类型的活动,我想要销毁会话.此时5个用户自动重定向索引页面.这怎么可能?可以在php中进行会话处理,为此我必须维护或更新用户登录时间.
Y U*_*ORK 51
满容易:
if(time() - $_SESSION['timestamp'] > 900) { //subtract new timestamp from the old one
echo"<script>alert('15 Minutes over!');</script>";
unset($_SESSION['username'], $_SESSION['password'], $_SESSION['timestamp']);
$_SESSION['logged_in'] = false;
header("Location: " . index.php); //redirect to index.php
exit;
} else {
$_SESSION['timestamp'] = time(); //set new timestamp
}
Run Code Online (Sandbox Code Playgroud)
小智 15
我从Sitepoint.com获得了这个解决方案,在你的html中使用了一个简单的元标记
<meta http-equiv="refresh" content="900;url=logout.php" />
Run Code Online (Sandbox Code Playgroud)
900是您希望会话在非活动状态下终止的时间(以秒为单位).
希望这对你有用