javascript - Whats the easiest way to determine if a user is online? (PHP/MYSQL) -


Is there a way that I can tell when a user is online?

Ie: Use logon, I set the $ _SESSION variable, out of user times - cookie trash collector updates the database to update their status as offline.

Edit: I want a solution that does not include time or dates. I want to ride some sessions or something like this. If someone is online then I am not enough to require it, so I have to guess what I want

The difference between timezones is not necessary.

Every time a user accesses a page, then update a field in their records in the user table, which is a previous-update-time. Then make a query for all users with the last update time within the last 5 minutes. Anything more than this, and they are considered "offline".

If you use your server-time, then through the NOW () function in MySQL, you can calculate the difference between the time-zone.

This is currently the standard way of tracking how many users (meaning, active in the last few minutes) online.

Frequently updated

If you want to know that they are still active, when they are not jumping from page to page, then 60 seconds or your own Add a little bit of javascript to ping the server to tell you that they are still alive. This will work as my original suggestion, but it will update your records at least once every five minutes without the need to browse your site.

  var stillAlive = setInterval (function () {/ * XHR uses back example in the example jQuery * / $ .get ("stillAlive.php");}, 60000);  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -