counting CURRENT site visitors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • toedipper

    counting CURRENT site visitors

    Hello,

    I am developing a site using php and mysql and I would like to be able to
    let visitors know how many other visitors are currently browsing the site
    i.e. 'There are currently x amount of visitors browsing this site'

    You can see this in action in the following sites but I am not sure what
    technology they use www.recruitni.com (about 1/3 down the page) and also
    www.scancom.co.uk on the left hand side.

    Is this possible using PHP and can anyone point me in the direction of how
    to achieve it?

    Thanks.

    td

    Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.




  • Michael Fesser

    #2
    Re: counting CURRENT site visitors

    .oO(toedipper)
    [color=blue]
    >I am developing a site using php and mysql and I would like to be able to
    >let visitors know how many other visitors are currently browsing the site
    >i.e. 'There are currently x amount of visitors browsing this site'[/color]

    If you want the value to be accurate -- impossible.
    [color=blue]
    >You can see this in action in the following sites but I am not sure what
    >technology they use www.recruitni.com (about 1/3 down the page) and also
    >www.scancom.co.uk on the left hand side.[/color]

    HTTP is a stateless protocol, there's no way to determine how many
    visitors are currently "online", because there simply is no way to
    identify unique users except for an explicit login. It's all based on
    estimations (for example the amount of requests from different IPs in
    the last 10 minutes) and as useless as a hitcounter for a visitor. The
    number of currently browsing users or page hits says absolutely nothing
    about a site's quality.

    Micha

    Comment

    • Ghizmo

      #3
      Re: counting CURRENT site visitors

      On Sat, 22 Jan 2005 22:50:05 -0000, "toedipper"
      <send_rubbish_h ere734@hotmail. com> wrote:
      [color=blue]
      >I am developing a site using php and mysql and I would like to be able to
      >let visitors know how many other visitors are currently browsing the site
      >i.e. 'There are currently x amount of visitors browsing this site'[/color]

      For my website I use this method...

      $timestamp=time ();

      // 10 minutes of timeout
      $timeout=$times tamp-6000;

      mysql_query("IN SERT INTO online (time,ip) VALUES
      ('$timestamp',' $REMOTE_ADDR')" );

      // purge all old users
      mysql_query("DE LETE FROM online WHERE ora < $timeout");

      // delete my own ip adress from statistic
      mysql_query("DE LETE FROM online WHERE ip = 'xxx.xxx.xxxx.x xxx'");

      $result=mysql_q uery("SELECT DISTINCT ip FROM online");
      $user=mysql_num _rows($result);

      echo $user;




      Comment

      • RavenSlay3r

        #4
        Re: counting CURRENT site visitors

        Nearly exactly what I was going to say Ghizmo.

        The simpliest way is to write a script that inserts (or updates) the IP
        and Time/date in a DB table. Then count the # of unique IP's and puge
        the old one's. Most sites look at a 10 min. interval for this purpose;
        given the nature of HTTP.

        Call [the file] "userCount. php" or somthing and include it at the top
        of your header so it's called on every page hit.

        ------
        I'm going to modify Ghizmo's code to show what I was thinking. Haven't
        tested this but I'm 99% sure it's right (and more efficent).

        REPLACE should INSERT the value if the record doesn't exist and DELETE
        & INSERT if it does, keeping the IP coloumn unique.

        (if you try this let me know how it works.)

        ------
        // ** Begin userCount.php **//

        $timestamp=time ();

        // 10 minutes of timeout
        $timeout=$times tamp-6000;

        // REPLACE instead of INSERT
        mysql_query("RE PLACE INTO online (time,ip) VALUES
        ('$timestamp',' $REMOTE_ADDR')
        WHERE ip = '$REMOTE_ADDR') ";

        // purge all old users
        mysql_query("DE LETE FROM online WHERE time < $timeout");

        // delete my own ip adress from statistic
        mysql_query("DE LETE FROM online WHERE ip = 'xxx.xxx.xxxx.x xxx'");

        $result=mysql_q uery("SELECT ip FROM online");
        $user=mysql_num _rows($result);
        echo $user;

        // ** End userCount.php **//

        Comment

        • Ghizmo

          #5
          Re: counting CURRENT site visitors

          On 23 Jan 2005 01:26:40 -0800, "RavenSlay3 r" <ravenslay3r@gm ail.com>
          wrote:
          [color=blue]
          >Nearly exactly what I was going to say Ghizmo.
          >REPLACE should INSERT the value if the record doesn't exist and DELETE
          >& INSERT if it does, keeping the IP coloumn unique.[/color]

          Thanks Raven for completing my script. The reason of the Insert in my
          script is because I it to keep track of all the movments in my
          website. My complete Query is

          mysql_query("IN SERT INTO online (time,ip,where) VALUES
          ('$timestamp',' $REMOTE_ADDR',' $PHP_SELF')");

          and keep records for 24hours instead of 10 minutes.
          So I can see exactly where the user moves.

          Bye bye


          Salutoni,
          Ghizmo
          ---------
          -----------
          ------------
          Webmaster di

          ---------------------

          Comment

          • R. Rajesh Jeba Anbiah

            #6
            Re: counting CURRENT site visitors

            toedipper wrote:[color=blue]
            > Hello,
            >
            > I am developing a site using php and mysql and I would like to be[/color]
            able to[color=blue]
            > let visitors know how many other visitors are currently browsing the[/color]
            site[color=blue]
            > i.e. 'There are currently x amount of visitors browsing this site'
            >
            > You can see this in action in the following sites but I am not sure[/color]
            what[color=blue]
            > technology they use www.recruitni.com (about 1/3 down the page) and[/color]
            also[color=blue]
            > www.scancom.co.uk on the left hand side.
            >
            > Is this possible using PHP and can anyone point me in the direction[/color]
            of how[color=blue]
            > to achieve it?[/color]

            This is much easier if you use custom DB based session handler
            <http://in.php.net/session_set_sav e_handler>

            --
            <?php echo 'Just another PHP saint'; ?>
            Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

            Comment

            Working...