December 28th, 2001, 03:23 PM
document.write? Help please
I have installed a cookie to remember a users name and password.
I would like to show who is online. So far I can only show one user. <script>document.write(yourname)</script>
How can I show all names online, and or a users online count?
Thanks in advance
January 7th, 2002, 01:32 AM
I think you are oversimplifying the problem a little.
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.