-1

How can i handle the situation when the a logged in user open two tabs and logs out from any one of that opened tabs. I need to make the other browser tab know that user is logged out. and denies any other requests from the user from the client side itself.

I am using PHP/Kohana

logeeks
  • 4,849
  • 15
  • 62
  • 93
  • 1
    You don't need to do that. Your responsibility is not to control the browser nor browsing preferences of your users. If the user is logged out at first tab, any action he performs at 2nd one should and must determine they're not logged in and cannot proceed further. – N.B. Aug 27 '14 at 10:37

3 Answers3

1

While I mostly agree with N.B. ("you probably do not need to do anything"), I can think of a couple of options:

  • Your pages could poll your server and check the session status.
  • Your log-out page could update a cookie or the Local Storage. Other pages would poll this location instead of your server.
Community
  • 1
  • 1
RandomSeed
  • 29,301
  • 6
  • 52
  • 87
1

There are number of ways to do this. One if redirect route using Kohana request Two using javascript to check and reload.

Bastin Robin
  • 907
  • 16
  • 30
0

Using kohana way it could be simple. In you main controller that you are extending, or using, use before function where you will determine if user is logged in and take some action if yes or not. Just use kohana Auth module to logg in user, for ex:

Auth::instance()->login($username, $password);

Then kohana will automatically save that user as logged in. You before function should contain something like:

if (!Auth::instance()->logged_in())
{
    //redirect to login page
}

This way you will check if user is logged in when he will try to open other page. If you are using also ajax, that should be also applied to main ajax controller in same way.

Then to log out user use:

Auth::instance()->logout();
Grzesiek
  • 442
  • 4
  • 15
  • I am currently using this approach, but kohana auth is thinking the user is still logged in even after the user is logged out using a different tab under a browser. – logeeks Aug 27 '14 at 13:14
  • Hmm... Are you using Auth::instance()->logout(); to logout user? If yes, are you also sure that before method is called on that page what is not working for you? It is worth to check or just show your code... – Grzesiek Aug 27 '14 at 13:20