我这里有一个函数idleTimer。我想在 5000 毫秒过去时销毁该功能并重定向到登录页面。在五秒钟过去并且我重定向到另一个页面之前, session 已经被销毁。我希望 session_destroy 仅在五秒后发生...使用此代码,重定向可以工作,但就像我之前所说, session 在 5 秒前被销毁。
有人可以帮助我吗?
function idleTimer()
{
var t;
window.onload = resetTimer;
window.onmousemove = resetTimer; // catches mouse movements
window.onmousedown = resetTimer; // catches mouse movements
window.onclick = resetTimer; // catches mouse clicks
window.onscroll = resetTimer; // catches scrolling
window.onkeypress = resetTimer; //catches keyboard actions
function logout()
{
<?php
session_destroy(); // the problem is here!
?>
window.location.href = './Login.html';
}
function resetTimer()
{
clearTimeout(t);
t = setTimeout(logout, 5000);
}
}
最佳答案
window.location.href = './Login.php?sessionDestroy=true';
文件login.php:
if(isset($_GET['sessionDestroy')){
session_destroy();
}
不要忘记将登录文件扩展名更改为 php
关于javascript - 我的 session 在到达设定时间之前就结束了...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61483061/