Online status indicator

liunx

Guest
As I've mentioned before, I'm coding a community with users, pm's, forum, the works. All in PHP and MySQL.
What I'm wondering about, is how to see what users that are currently 'online' on the site, surfing the site. Much like this forum in fact. With this forum you can even see where people surf!

I have a system now, but it's not very satisfying. Basically it works like this; When someone logs in, or views a page on the site, a 'last seen' date and time is written in the database. This date and time is later used for listing a user as offline or online. If the last seen date and time are no older than 3 minutes, a user is online.
As you might imagine, this causes some problems.. If a user is idle for more than 3 min, he/she is shown as offline, although maybe just idling on the page with the java irc chat client or something. And if a user logs out, or leaves the site, he/she is still shown as online for another 3 min.

So what I'm wondering, is how to make a system that works like the one on this site. A user should be displayed as online when using the site, although he/she might be idling. The users should be displayed as offline if they leave the site, close the browser window, or log out. I would also like to see how many 'guests' that are surfing the site. How is this accomplished?

I have found one system once, but the code was probably close to 15kB, so I didnt even bother reading it, I don't want a simple thing such as this to consume that much CPU power. I don't remember where I found it anyway, or what it could really do.

The only thing I can think of that maybe could accomplish this system, would be PHP sessions. I am currently using sessions for browsing the site. Is there maybe some way to see what sessions that are active?

Well, I appreciate any tips, ideas and help in this!


Please note that I'm not demanding anybody to blurt out the complete source code for such a system here, I just want to know the theory of how it's accomplished. But if there are functions and such that could help me in this, that aren't really common PHP knowledge, please feel free to mention them!

:rocker:I am sure this link here will help you out
<!-- m --><a class="postlink" href="http://arc.ireed.net/tutors/archive/php/001/index.php">http://arc.ireed.net/tutors/archive/php/001/index.php</a><!-- m -->

good luck :)Well, you are wrong :) Did you read my entire post? Maybe it was too long to keep people's attention, hehe. What you posted is even worse than my current system, so I'm afraid it doesn't help... Thanks anyway :Dthis thread should help.

<!-- m --><a class="postlink" href="http://www.htmlforums.com/showthread.php?s=&threadid=17349Well">http://www.htmlforums.com/showthread.ph ... =17349Well</a><!-- m --> I read that thread scoutt, but it's a bit confusing.. And it's mostly about the 'new posts' feature. I still don't really understand how it's done, how I can tell when people are on my site or not.. It seems like you know how it's done though.. and you even have access to the forum code ;) Could you maybe please explain it here, all in one piece? Nothing essay like, just a brief description of how it would work...? :)well this is how it is done.

the thread I posted is the samething. all users are inserted into a table called "sessions". the time and user id (if cookie is present) and page they are on and the session of the browser.

then you will have some code that will update that sessions table every so often, say 5 minutes. this is called the cookie timeout or what ever you want.

like this forum, your session is updated every 5 minutes I believe. So I can sit idle for 10 minutes, and theorectically it should not show me online at the site, and then once I refresh it will update the time in that session table then show be back online. all users that are online will be in this table, members or not, if they are members than the user id is added, but non-members have a id of 0, those are guests.

that is it in a bottle. same as that thread it tells about sessions.

I suppose there are number of ways to do it, so this is one way.I got a few questions about this too

-After i read that thread (not full-detailed) sessions are (also)(temporarily)stored on the server. What information of a session is stored on the server ?

-Also is there a way i can view the active sessions (and their information)

-When i register/attach a variable to that session, is that also (temporarily) stored on the server ?

-And is their a way for me to also view this registered variables ?

example":
I create a login page, using sessions. When a users succesfully logins a variable is created with his username as value.

how would i 'loop' thru all that variables that are stored on the server

This would be very handy for a online script. Because when a browser is closed, that session destroys, along with it's variables.

Excuse me if i ask questions that make no sense. i dind't fully detailed read thru that thread.Originally posted by yoda
I got a few questions about this too

-After i read that thread (not full-detailed) sessions are (also)(temporarily)stored on the server. What information of a session is stored on the server ?
anything you want in the session.


-Also is there a way i can view the active sessions (and their information)
just echo the $_SESSION - all it is is an array.
print_r($_SESSION);

tha tiwll print out all of the session variables that are associated to your browsers session.

-When i register/attach a variable to that session, is that also (temporarily) stored on the server ?
why woun't it be? you can save anyhtin you want.

-And is their a way for me to also view this registered variables ?

example":
I create a login page, using sessions. When a users succesfully logins a variable is created with his username as value.

how would i 'loop' thru all that variables that are stored on the server

This would be very handy for a online script. Because when a browser is closed, that session destroys, along with it's variables.

Excuse me if i ask questions that make no sense. i dind't fully detailed read thru that thread.
the last 2 questions are just repeats. you can save anything and view anything you save. a session is just a cookie, so if you can save it in a cookie than you can ave it in a session.

you can't loop through all of them, only the ones that are stored on the server that have your borwser session id. BUT, you could just open the folder that these are stored in, if you knew where it is, and echo out all of them. bu tI don't know why as you can only use some of them.I used session_save_path to get the current directory used to save data. got /tmp out of it. tried to open that dir, but it gave me SAVE MOdE restrictions errohs. :rocker: :rocker: :rocker: :rocker:
 
Back
Top