如何处理浏览器“多个”选项卡中的用户注销?从其中一个注销时自动注销所有打开的选项卡

问题描述:

朋友您好,当我从其中一个注销时,我需要自动注销所有打开的选项卡

Hello friends I need to auto logout my all the open tabs when logout from one of them

我已经尝试了以下讨论链接
中的以下代码如何处理浏览器多个标签中的用户注销? / a>

I hava tried following code from this previous discussion link How to handle the user logout in browser multiple tab?

代码:-

<script type="text/javascript">
function readCookie(name) {
    var nameEQ = escape(name) + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) === ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) === 0) return unescape(c.substring(nameEQ.length, c.length));
    }
    return null;
}
window.setInterval(function() {
    if(readCookie('loggedout')==1) {
        window.location.assign('loggedout.html');
        //Or whatever else you want!
    }
},1000);
</script>

我要在所有页面
中放置此代码页脚,而不是在注销时设置cookie。 php by setcookie('loggedout',1)函数
并在登录页面顶部取消设置cookie

I hava place this code footer of all the pages than I set cookies in logout.php by setcookie('loggedout',1) function and unset cookie at top of the login page

但奇怪的是
可以正常工作对于某些页面来说很好,以防万一我下次尝试登录
然后成功登录但在1秒钟后它会自动注销我

but the strange things are it works well for some pages and in case it works next time if I try login then login successfully but after 1 second it logouts me automatically

请让我知道什么这段代码的问题,并且您中的任何一个都对此主题有更好的建议。

please let me know whats the problem with this code and any one of you have better regarding this topic please help me

如何取消设置cookie?

How you unset the cookie??

如果您使用 unset($ _ COOKIE ['loggedout']);

然后将其替换为 setcookie('loggedout');

cookie使用: setcookie('loggedout',1);

That is for set cookie use: setcookie('loggedout',1);

未设置cookie使用: setcookie('loggedout');

for unset cookie use: setcookie('loggedout');

这对我有用。