1

Possible Duplicate:
Check if user is offline

I'm building a community website. Users will login and logout as usually. I use the attribute status online/offline to set the user's status. But what if a user just clicks the X button or disconnects otherwise without logging out? it shows login status.How i get to know user is currently online or not ?

Community
  • 1
  • 1
Inforian
  • 1,716
  • 5
  • 21
  • 42

2 Answers2

11

You have three options:

  1. You can assume the user is offline if they don't load a new page within a specific period of time (e.g. 10 minutes). This would be done by keeping a "last page load time" for each user on the server.

  2. You can have a script on your pages that fires off an AJAX call every so often to tell the server "I'm still here" - this would use the same logic as #1, but would be somewhat more reliable.

  3. You can use a page-unload AJAX call to tell the server when the browser is unloading the page, and mark the user as offline until they load another page.

Amber
  • 507,862
  • 82
  • 626
  • 550
0

I would use an ajax to make an update the user`s table (every 5 min), if the last update was at most 4 min he is online, 10 min ago then he just left, greater than 15 offline. Or there is a thred on Node js here Advice on implementing "presence" for a web site?

Community
  • 1
  • 1
ka_lin
  • 9,329
  • 6
  • 35
  • 56