Welcome Guest, Not a member yet? Register   Sign In
online/offline status
#1

[eluser]new_igniter[/eluser]
Hello,
Can anyone who has created user status (whose online and whose offline) share some approaches you would use? Is this something that can be done at the session level?
-Peter
#2

[eluser]Wuushu[/eluser]
I dunno, never done it before but an idea maybe is having your pageviews constantly writing to your session table, or user table in the DB with your last_activity timestamp..

and then join that on your user table, with something like

Code:
if($row['last_activity'] > time() - 60*5)
   echo "online!";
else
   echo "offline";
#3

[eluser]Pygon[/eluser]
Aye -- although i would use a standalone activity table keyed on crossreference user_id and having last_activity giving you the ability to SELECT > now() - X minutes and joining the user table on the results (rather than joining on to the user table and having PHP determine online status).

Course, it depends on whether you're displaying status for one user, only online users, or all users as to how you should write your join.

But yeah.
#4

[eluser]adamp1[/eluser]
The normal way of doing it I believe is to have a separate table to store the session ID and when they visited. Then on each page loads it updates the time for their session variable they were last seen. Then you just delete ones which haven't re-loaded a page every so many minutes.

Same principle I think as Pygon suggested.
#5

[eluser]new_igniter[/eluser]
Ok, very cool! Is there a way to do something when the browser closes? I think I could get the table to show online and idle easy enough, but I am curious how do I show offline when they close the window?
#6

[eluser]adamp1[/eluser]
I would of thought when you do the query to the database to get all session_ids which were refreshed in the last 5mins then any other users not returned in this query (IE ones not currently live in the last 5mins) would be offline.
#7

[eluser]new_igniter[/eluser]
Thanks adamp1 and pyong




Theme © iAndrew 2016 - Forum software by © MyBB