Tuesday, September 7, 2010

How to detect if the user is logout in php?

You cannot detect when a user closes their browser or navigates off your site with PHP, and the JavaScript techniques of doing so are so far from guaranteed as to be useless.
Instead, your best bet is most likely to store each user's last activity time.
  • Create a column in your user table along the lines of 'last_activity'.
  • Whenever a user loads a page, update their last_activity to the current time.
  • To get a list of who's online, just query the database for users with last_activity values more recent than 10/20/whatever minutes ago.

Source: http://stackoverflow.com/questions/887919/how-to-detect-if-the-user-is-logout-in-php

No comments:

Post a Comment