#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Location
    Australia
    Posts
    42
    Rep Power
    14
    I am looking to Count the number of users on the website, without having the user loggin. I have found code which does this but it is in ASP http://www.asp101.com/resources/active_users.asp , this uses Session and Application variables, it checks when a session starts and adds 1 to an Application variable, and when a session finishes it minus 1 from the same Application variable. I read that PHP doesn't have Application variables, only Session. Is it possible to add a Global variable in the php.ini to be used the same way? or is there a better way to do this. Please don't reply with a Database suggestion, as this problem doesn't require one, this is for a site with high traffic.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 1999
    Location
    Denmark
    Posts
    83
    Rep Power
    15
    you could use sessions to controle users on your site, add one to a global session variable when a user enters, and minus one when they leave, you could set a cookie on the users computer or you could send a variable to every site to track the user.
    when you are using sessions there is a "defined" SID variable which is set on session start and that variable is unique for every user.

    hope this will lead you on your way

    ------------------
    regds..
    -ulrik-

    [This message has been edited by Ulrik N (edited October 23, 2000).]
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Location
    Australia
    Posts
    42
    Rep Power
    14
    Where do you setup the Global Variable? in the php.ini file?

    How do you determine what the User has left the site, How do I capture the ending of a session with PHP??
  6. #4
  7. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    6
    Rep Power
    0
    session_start();
    if(session_is_registered("USER_IS_HERE")
    {
    session_register("USER_IS_HERE");
    $fp = fopen("counter.cnt","r+");
    $counterval = fread($fp, 26 );
    rewind( $fp );
    $counterval = (integer)$counterval + 1;
    fwrite( $fp, $counterval, 26);
    fclose( $fp );

    print "Total unique visitors are :".$counterval;
    }

    ps, don't forget to chmod 666 counter.cnt

    ------------------
    Greetings lewi
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Location
    Australia
    Posts
    42
    Rep Power
    14
    Thank Lewi, just one more question, do I need to put this on all pages, or is there a file I can but it in the is continually read, like the php.ini file.
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Location
    Australia
    Posts
    42
    Rep Power
    14
    Now I need to be able to determine when the users session stops. Is there a flag or anything which is set went a session is closed by the user.
  12. #7
  13. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    6
    Rep Power
    0
    u can put the code in a include file
    so u only have to put that line in every file

    like:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    include("phpcounter.inc");
    [/code]

    as far as i know your are unable to directly see i a user logs of your site, it could be
    done with java
    or you could check for a period of time of user inactivity (this is the simples way)

    ------------------
    Greetings lewi
  14. #8
  15. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Location
    Australia
    Posts
    42
    Rep Power
    14
    Well what I have ended up doing and currently testing is recording a time stamp and IP address in a file, so basically when the script is run it will check each line in File 'A' and write it file 'B' when checking if the datestamp is old (say 10-15 minutes) it will not copy it, and if the IP is the same as the current user it will update the time stamp, during this time I count the number of users and then copy file 'B' back over file 'A'.

Similar Threads

  1. Sessions not working for certain users
    By Nate88 in forum PHP Development
    Replies: 8
    Last Post: September 14th, 2004, 07:16 AM
  2. count the visits
    By Presfox in forum PHP Development
    Replies: 2
    Last Post: February 15th, 2004, 07:44 PM
  3. Replies: 1
    Last Post: January 30th, 2004, 02:10 AM
  4. Replies: 0
    Last Post: January 27th, 2004, 10:16 AM
  5. Site, server, connection, concurrent users
    By Tantalus in forum Apache Development
    Replies: 0
    Last Post: January 12th, 2004, 05:25 PM

IMN logo majestic logo threadwatch logo seochat tools logo