且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用jQuery调用php注销脚本

更新时间:2023-12-05 18:38:04

对我来说看起来不错,但我建议做一下简化.***的方法是使用setTimeout函数中包含的代码,并在其中检查用户上次活动的时间.因此,设置一个像'lastActive'这样的变量,并使用类似以下内容:

Well it looks good to me, but I would suggest a bit of a simplification. The best way to do it would be to use the code you have within the setTimeout function, and within it check when the user was last active. So set up a variable like 'lastActive', and using something like:

$(document).click(function(){ 
    var currentTime = new Date();
    lastActive = currentTime.getSeconds();        
});

然后在setTimeout函数中执行以下操作:

Then in your setTimeout function you do something like:

var currentTime = new Date();
if(lastActive + 5000 < currentTime.getSeconds()){
    //If user hasn't been active for 5 seconds...
    //AJAX call to PHP script
}else {
    setTimeout(theSameFunction(),5000);
}

然后在您的PHP中仅破坏会话,然后成功回调函数应仅具有:

Then in your PHP simply destroy the session, and the success callback function should then simply have:

window.location = 'index_test.php';

发送途中的用户.