phpsession-timeout

How to make online/offline


I have a login system. With my login session stores and cookies (if you "remember me") and then you login. When you're inside the login system at home.php (you can only enter if session/cookie is registered), i want the status field in "user" table, to update to online and offline when you sign out.

I know how to do this, to update the status when you login and log out, but here's the thing: How do i do when the user leaves the site without logging out (pressing on the actual log out button) ? I mean if the status is set to Online and you leave the page, it will remain Online you may understand..logic.. so what do i do at this situation? I don't want to have a little ugly popup that log you off when you leave the page, that's so old school and bad.

Or maybe when the session runs out then you set the status to offline? but again, how should i do that?

Ideas and examples on solution for this would be good.

Sites like e.g facebook, in the Chat you change status to Idle if you leave the pages, and somehow if you leave the page and there goes some time you are offline... How, I don't know.


Solution

  • Facebook is a bit nasty in that their page contains some Javascript that keeps an open connection to their chat server. Once the connection is lost, it means you've closed the page (or your internet connection) and you're marked offline.

    Usually, just a timeout is used that marks the user offline some time after their last activity/page load. A reasonable value for this timeout could for instance be the time after which their session cookie expires.