SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist Caesar's Avatar
    Join Date
    May 2000
    Location
    On some harddisk
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let's say that I wish to display the number of visitors currently logged on my site.

    How can I do that with PHP?
    Thanks!

  2. #2
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's a difficult one to do as you have no idea if someone has left your site, it can be done but only in an approximate way.

    A better way would be to use a Java applet to do the job as it knows when someone leaves your site, there are some available as I have seen them in use, but I don't know where to get them from.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Sausalito, Ca
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have thought about this as well, just because I think it would be kinda cool. The only way that I can think of is by use of sessions. I think that you would have to store session info either in a session file on the server (which is how I am currently doing it), or in a database. If it were in a session file, I know that you can set up the php.ini file to clean up garbage session files after a given period of time. So one could probably count open the session files that are in the directory where they are kept, and return the names from the session files. The problem I see with this way is that if you delete a session file too soon, it could cause frustration for your users requiring them to login in every time they have left their computer for five minutes.

    If you were to use a database to store session info, I think it would be a lot easier. When someone is logged in it would set a column in the session table to true. You could run a query that returned all the user names where login=true. I guess though it doesn't matter either way, as in a session file you would be tracking if they were logged in or not as well, so you could loop through the session files and grab the names from those where login=true.

    Anyway, just some ideas, I've never tried it. But I would like to learn how to do it also.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •