【发布时间】:2017-08-13 11:37:48
【问题描述】:
我试图在用户处于非活动状态 10 秒或更长时间后在我的 php 应用程序中实现自动注销。我的代码一切正常,唯一的问题是要进行注销,用户必须再次单击屏幕。我希望警报消息和注销自动发生而无需任何点击。这是我的代码的 sn-p:
if (isset($_SESSION['last_action']))
{
//Figure out how many seconds have passed
//since the user was last active.
$secondsInactive = time() - $_SESSION['last_action'];
//Convert our minutes into seconds.
$expireAfterSeconds = 10;
//Check to see if they have been inactive for too long.
if($secondsInactive >= $expireAfterSeconds){
//User has been inactive for too long.
//Kill their session.
echo "<script>
alert('You have been logged out');
window.location.href='../clinician/logout.php';
</script>";
}
}
【问题讨论】:
-
你需要在Javascript中为此设置一个计时器。
-
这可以通过 JavaSciprt 使用
setInterval()函数轻松完成。 -
Php 是一种服务器端编程语言,只执行一次。要在网站会话期间自动进行,您必须为此使用 javascript。
标签: javascript php html xampp