
January 7th, 2002, 12:32 AM
|
 |
Web Developer
|
|
Join Date: Oct 2001
Location: Pennsylvania
Posts: 171
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Re:
I think you are oversimplifying the problem a little.
What you probably want isn't Java, or even JavaScript for that matter. Try using PHP and SQL to accomplish your task.
I never did this, and I dont think I will ever have the use for it, but I am going to just ramble off the top of my head as to how it should be done:
1. Set a session cookie whenever the user logs in.
2. When you write the session cookie, add their name to a table in your SQL database.
3. The page that contains the user count could contain a simple query to the database to fetch the number of rows in the table, which will then return number of users that have sessions currently set.
4. When you destroy the session cookie, delete that row from the table that contains the username.
That is putting a lot of extra work on the SQL server, and the webserver. You are looking at about a minumum of 3 queries per user, assuming they only see the count on ONE page. If the count is in a header or an included file, its another query everytime that file is loaded. All that to display a little number. Now if you are going to do some sort of instant messaging between online users or something like that, it might be worth it. But to display the number of users, it might be a little too much.
|