CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 How do I display amount of people online?

Print topic Send  topic

Author Message
spaceclown
Posted: 04/17/2002, 10:22 AM

How do I display the amount of people online? amount of logged in members online, and members in general?
Jon Westfall
Posted: 04/17/2002, 10:26 AM

The forum here has a lot of examples of similar things as this, but to conceptualize it in broad terms, the following would work:

1. Add a column in your user table named something like 'online'.
2. Upon login, add a line of code that changes that online value from 0 to 1 (or something similar) for the user logging in.
3. Simply output a select command (something like select username from users where active=1;) from the SQL server and display it on your site. If you just want numbers, just see how many results are returned.

Hope that helps give you a concept - just search the forums, you'll find more.

Jon Westfall.
DJOldenburg
Posted: 04/18/2002, 8:09 AM

I've done what Jon has suggested in the past. The one downside is that if the user doesnt properly LOG-OFF, the the flag never gets set back to 0 (offline).

Dj
Jon Westfall
Posted: 04/18/2002, 9:43 AM

I hadn't thought of that... possibly recording a time in a file and then checking every x min (through a cron job or something similar) to see if the user is still active. This requires a lot more work though.
Brent
Posted: 04/18/2002, 1:25 PM

>I hadn't thought of that... possibly recording a time in a file and then checking every x min
>(through a cron job or something similar) to see if the user is still active. This requires a lot
>more work though.

You can of course update this table with the current date&time, when the user displays
any page. Of course in order to reduce the amount of I/O to the database, you could
have it update the table every 5 minutes by comparing the current time to a
session variable $last_time_alive (the time the table was last updated). When the
difference is greater than 5 minutes, write the current time to the table and also update
the $last_time_alive session variable. When the user formally logs out, of
course set the OnLine field in the record to 0.

Also when the table is being updated (every 5 minutes), this is another
opportunity to look for other peoples records that are too old. If there
are records that say they are Online and older than 10 minutes, set Online to 0.
This catches the people who have left the site without logging out. If the user
fell asleep and then simply displays a new page after 15 minutes, the code will
update his record automatically (because a new page is displayed and the time
is > 5 minutes) to say that he is still alive.

So you don't need a daemon running in the background to do it. Each user will
clean up the offline members for you. :)
Tomasz
Posted: 04/18/2002, 4:01 PM

I have simple idea;

maybe it would be enough to search through session files, looking for UserID and UserRights.
Easch session file contains e.g: UserID|s:1:"1";UserRights|s:1:"3";

Just count session files which contain 'UserID' and 'UserRights' words and you have users online:-)

If somebody finds this useful and knows php, pls write script and submit here.

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.