This topic is locked

Who's logged In?

1/10/2007 5:50:04 PM
PHPRunner General questions
J
JZint author

I have my site set up with username and passwords set up on User Groups. Is there a way to set up a Who's logged in box down in a corner some where, say like on the main menu of the site and also maybe the number of guests that are logged in as well.

Sergey Kornilov admin 1/10/2007

I don't have a ready to go script for this however here is the idea.
It's easy to track logged in users if they log out leaving the site. The problem is that most of them simply close browser window and you never know if they still on the website. As a workaround you need to track their activity on website and after a certain period of inactivity you can believe they are gone.

  1. Add a field named LastAccessTime (datetime) to login table.
  2. Add a code to header.php that updates current logged user record with the current timestamp.
  3. Script that retrieves a number of logged in user should only select record where the difference between LastAccessTime and current time is less than 20 minutes. Script can be placed to header.php or to footer.php file.
    The method is not 100% accurate however it's based on what technology we have to this moment.
    Another, more precise method uses AJAX. Basically it makes each user's browser to ping server every 5-10 seconds telling "I'm still here".

    The major drawback is increased web server and database load which would kill websites with decent traffic.
    I hope this helps a bit.