JavaScript由于多个选项卡中的不活动而将用户注销

时间:2016-11-29 09:54:21

标签: javascript php jquery session

由于不活动,我使用此post下面的javaScript代码将用户重定向到注销页面。

如果用户在同一网站上打开多个窗口,则无法使用。例如,如果用户打开一个窗口,则在10分钟后打开另一个窗口。第一个窗口将重定向到注销页面以终止用户的会话,因为用户在过去15分钟内仍处于活动模式。

有没有办法做到这一点?

<body onmousemove="reset_interval()" onclick="reset_interval()" onkeypress="reset_interval()" onscroll="reset_interval()">


<script type="text/javascript">
function set_interval()
{
//the interval 'timer' is set as soon as the page loads
timer=setInterval("auto_logout()",10000);
// the figure '10000' above indicates how many milliseconds the timer be set to.
//Eg: to set it to 5 mins, calculate 5min= 5x60=300 sec = 300,000 millisec. So set it to 3000000
}

function reset_interval()
{
//resets the timer. The timer is reset on each of the below events:
// 1. mousemove   2. mouseclick   3. key press 4. scroliing
//first step: clear the existing timer
clearInterval(timer);
//second step: implement the timer again
timer=setInterval("auto_logout()",10000);
..completed the reset of the timer
}

function auto_logout()
{
//this function will redirect the user to the logout script
window.location="your_logout_script_location_here";
}
</script>

0 个答案:

没有答案
相关问题