0

Let's say you have a user who's logged into his account on a website and has opened multiple pages using lots of tabs.

He then logs out in one of those tabs and continues doing other stuff but then decides to return to the website.

Now, he may have forgotten he logged out and clicked on something in one of the remaining opened tabs but whatever he's clicked requires him to have been logged in to see it - this means the PHP page will display an error message.

Now my question is: How does one make a browser notice a user has logged out across multiple tabs. Sort of like how Facebook does it - if you have multiple tabs open and you log out using one and then open another it will show you a pop up box telling you to log in.

How is this done?

Because, obviously, in the case of such a thing happening, I wouldn't want a user seeing an error in my page.

CBroe
  • 91,630
  • 14
  • 92
  • 150
  • I guess you are referring to the use of Long Polling, SSE or Websockets. In very essence you have a permanent connection open to the server (in each tab), usually accomplished via JavaScript and/or HTML5, by which you can send messages back and forth. The server could generate a message on sign out that would be broadcast to all open connections in all tabs. You could catch that message and act upon that (show a notification, redirect, ...). I guess this would be a good read for you: http://stackoverflow.com/questions/11077857/what-are-long-polling-websockets-server-sent-events-sse-and-comet – Timusan Jul 06 '15 at 03:12

1 Answers1

0

you can save a flag in cookie for IsLoggedOut.

createCookie('IsLoggedOut','false',7);

function CheckIsLoggedOut()
{
 var x = readCookie('IsLoggedOut')
 if (x == "true") {
    //logout  and redirect to login page
 }
}

Update the cookie to true, when the user logs out in any tab.

createCookie('IsLoggedOut','true',7);

Check the cookie status in interval and if the status changed, then logout in all other tab.

setInterval(CheckIsLoggedOut, 1000);
Community
  • 1
  • 1
sudhansu63
  • 6,025
  • 4
  • 39
  • 52