#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Posts
    1
    Rep Power
    0

    document.write? Help please


    Hi all.

    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

    Rob
  2. #2
  3. Web Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Pennsylvania
    Posts
    171
    Rep 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.

IMN logo majestic logo threadwatch logo seochat tools logo