我有代码
if(isIdleTimeExceeded())
{
logout();
header("Location:".$baseurl."index.php");
exit();
}
在IdleTimeExceeded中我正在检查时间。
我想在会话到期后获得jQuery警告框。
答案 0 :(得分:2)
您发布的代码是PHP代码。但是在页面被发送到客户端之后,您将无法再访问php函数。如果空闲时间意味着用户没有在几秒钟内切换页面,那么您只需要javascript。
<script>
//the function IdleToLong will be called after 30seconds.
//This means if the page reloads, it starts over.
setTimeout(IdleToLong, 30 * 1000); // 30 seconds
function IdleToLong() {
alert('Move your ass');
//If you also need to logout in PHP then you must notify the server that a user has been idle to long.
$.get('logout.php?reason=idle').complete(function() {
window.location.href = '/';
});
}
</script>
答案 1 :(得分:0)
使用javascript创建警报
echo '<script type="text/javascript">alert("Logged out!!");</script>';