doubledee — 2012-03-04T21:33:39-05:00 — #1
I am looking for a better way to track a User's Online Status so I can set an "Online Status Indicator" like you would see in an Instant Messaging Application.
Ideally I would like to have 3 statuses:
- Online and Active (green)
- Online but Idle (yellow)
- Offline (grey)
Currently I set $_SESSION['loggedIn'] = TRUE; in my "log_in.php" script and then maintain that status by using session_start(); at the top of each page.
As far as I know, my current approach wouldn't always give you accurate readings like if a User is "idle" or if they leave my site.
spacephoenix — 2012-03-05T01:14:58-05:00 — #2
Is the session data currently being stored in the file system or in a database table?
doubledee — 2012-03-05T01:20:55-05:00 — #3
I have been saving it in the User's SESSION, but I just added some code so I have loggedIn and lastActivity stored in the User's record in the database.
wonshikee — 2012-03-05T01:38:20-05:00 — #4
It requires 2 layers. You can use just one or the other, but both will give a more real time reading. However realize that the internet is a stateless system, so the only way the server knows, is if the client sends information back.
1) Server side. Every time the user goes to a new page, or submits a form, you maintain the user as active.
doubledee — 2012-03-05T02:42:33-05:00 — #5
Right now I write to my database when a User Logs In or Logs Out. I update "logged_in" to "0" or "1" and "last_activity" gets NOW().
To back up a minute, what I am doing is this...
My website is full of Articles. Beneath each Article can be Comments. Next to each Comment, is the Poster's Username, Online Status, Photo, Location, and Comment.
I want the Poster's Online Status to entice Readers to post a Comment. (The logic being that if people think/see that others are online and Commenting, then they might be more inclined to do the same!!)
- If a Poster logs IN or OUT then their Online Status is updated
- If a Reader goes to an Article/Comments page, then the Reader will see a "snap-shot" of Posters who were On/Offline at that moment (sorta)
I am trying to add code that will update the Online Status every time a Poster navigates to another page.
serverstorm — 2012-03-05T10:23:54-05:00 — #6
Once a page loads and a user sits idle for a long time then without using AJAX you will not be able to keep this fresh, until the user loads a new page on your site, which at that point you could refresh everyone's status from querying active users in the Db.
doubledee — 2012-03-05T23:21:04-05:00 — #7
Don't you think that is good enough?
I mean if a Reader is sitting idle for an hour, then most people would understand that the page they are viewing is an hour old and may not reflect new updates.
When I learn AJAX I can make it more interactive, but I'm thinking what I said above should be "dynamic" enough for now...
What do you think?
serverstorm — 2012-03-06T09:39:56-05:00 — #8
system — 2014-10-07T22:03:58-04:00 — #9
This topic is now closed. New replies are no longer allowed.