[英]how to keep the session active even i opened in multiple tabs in same browser
i would like to implement one thing.i opened my site in multiple tabs. 我想实施一件事情。我在多个标签中打开了我的网站。 while i work in one tab others tabs should not be timedout.
当我在一个选项卡中工作时,其他选项卡不应超时。 it should be alive.
它应该还活着。 how to keep alive for other tabs.
如何为其他标签保持生命。 i used below js to find idle time logout.
我用下面的js查找空闲时间注销。
<script type="text/javascript">
idleTime = 0;
$(document).ready(function () {
//Increment the idle time counter every minute.
var idleInterval = setInterval("timerIncrement()", 60000); // 1 minute
//Zero the idle timer on mouse movement.
$(this).mousemove(function (e) {
idleTime = 0;
});
$(this).keypress(function (e) {
idleTime = 0;
});
})
function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime > 2) { // 30 minutes
var beforeTime = new Date()
var bminutes = beforeTime.getMinutes();
var bseconds = beforeTime.getSeconds();
var user='<?php echo Auth::getSessionUserFullName();?>';
if(user!='')
{
var timehours=beforeTime.getHours();
var timeoutmin=bminutes+1;
var timeoutseconds=bseconds-1;
if(timeoutseconds>59)
{
timeoutseconds=0;
timeoutmin=timeoutmin+1;
}
if(timeoutmin>59)
{
timeoutmin=0;
timehours=hours+1;
}
if(timehours>24)
{
timehours=0;
}
var ok=confirm("Your session expire time started at "+beforeTime.getHours()+":"+beforeTime.getMinutes()+":"+beforeTime.getSeconds()+".Please click 'OK' before "+timehours+":"+timeoutmin+":"+timeoutseconds+" to stay signed in.");
if(ok)
{
var currentTime = new Date()
var aminutes = currentTime.getMinutes();
var aseconds = currentTime.getSeconds();
var time=aminutes-bminutes;
if(aminutes>bminutes && aseconds>bseconds)
{
alert('Time out!!Please login again to access.');
window.location.href='<? echo APPLICATION_WEBROOT?>auth/logout';
return false;
}
else if(time>=2)
{
alert('Time out!!Please login again to access.');
window.location.href='<? echo APPLICATION_WEBROOT?>auth/logout';
return false;
}
else
{
return true;
}
}
else
{
window.location.href='<? echo APPLICATION_WEBROOT?>auth/logout';
}
}
}
}
</script>
Please help me. 请帮我。 how to keep the sessions for all opened tabs.thanks in advance
如何保持所有打开的选项卡的会话。
The session is not tab specific. 会话不是特定于选项卡的。 It is for the whole browser instance.
它适用于整个浏览器实例。
The session is extended when a user makes a request to the server. 当用户向服务器发出请求时,会话将扩展。 So depending on your application, you may have to generate regular requests to the server to extend that session.
因此,根据您的应用程序,您可能必须向服务器生成常规请求以扩展该会话。
For that, you can use the setInterval javascript function to trigger an AJAX call to your PHP backend. 为此,您可以使用setInterval javascript函数来触发对PHP后端的AJAX调用。
Hope that helps... 希望有帮助...
BTW: be careful because some browsers do deactivate the tabs which don't have the user focus (Chrome for example) - it will not modify session... but some JS could be suspended. 顺便说一句:请小心,因为某些浏览器会停用没有用户焦点的选项卡(例如Chrome)-它不会修改会话...但是某些JS可能会被暂停。
One of the way I can think of is handle the session yourself in the server. 我能想到的一种方法是自己在服务器中处理会话。
Here's a system that might work (welcome suggestions of improvement): 这是一个可能有效的系统(欢迎提出改进建议):
1) store your own custom session in server DB, with IP being the unique identifier. 1)将自己的自定义会话存储在服务器数据库中,其中IP是唯一标识符。
2) whenever user interacts with your server, grab its IP and update the corresponding session stored in server. 2)每当用户与您的服务器交互时,获取其IP并更新存储在服务器中的相应会话。 If that session has already timeout, redirect user to timeout page.
如果该会话已经超时,则将用户重定向到超时页面。
there might be many things that I haven't though through, but in my mind this should be a viable way to maintain session across tabs 可能有很多事情我还没有做完,但是在我看来,这应该是维护跨标签会话的一种可行方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.