1

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

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

Code:-

<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>

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

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

Community
  • 1
  • 1
Gangesh Bhat
  • 11
  • 1
  • 8

1 Answers1

0

How you unset the cookie??

If you use unset($_COOKIE['loggedout']);

then replace this with setcookie('loggedout');

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

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

This worked for me..

Deepu Sasidharan
  • 5,193
  • 10
  • 40
  • 97
  • thanks for your quick help this works for my admin module but not for other modules I try it with other modules but auto logout all tabs successfully but after I login again it automatically logout me after 1 seconds which we set in above code – Gangesh Bhat Aug 07 '14 at 13:02
  • Incase someone looking for some great answers: https://stackoverflow.com/questions/28230845/communication-between-tabs-or-windows – Bipul Roy Mar 27 '20 at 13:43