visitor counter using cookie

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

    visitor counter using cookie

    Hi all,
    This has been asked in the past in different ways. I'm still a bit
    confused about setting up counters. I'm quite new to php. I've read
    few tutorials about writing counters using cookie and sessions. It
    sounds quite straight-forward. But what I'm unsure about is- if the
    browser is set to accept cookies manually and the user blocks the
    cookie, what happens? I think in that case, the counter is not
    incremented because the value is not returned by the browser. Then we
    are likely to get inaccurate counters. Is there a way to get
    "accurate" counters?

    Thanx
    Ben
  • Erwin Moller

    #2
    Re: visitor counter using cookie

    Ben wrote:
    [color=blue]
    > Hi all,
    > This has been asked in the past in different ways. I'm still a bit
    > confused about setting up counters. I'm quite new to php. I've read
    > few tutorials about writing counters using cookie and sessions. It
    > sounds quite straight-forward. But what I'm unsure about is- if the
    > browser is set to accept cookies manually and the user blocks the
    > cookie, what happens? I think in that case, the counter is not
    > incremented because the value is not returned by the browser. Then we
    > are likely to get inaccurate counters. Is there a way to get
    > "accurate" counters?
    >
    > Thanx
    > Ben[/color]

    Hi Ben,

    I think the articles did confuse you a bit. :-)
    If you use a cookie for a visitorcounter, that counting only happens for
    THAT visitor. But cookies can be important, read on.

    You need to store somehow on the server how many visitors you have.

    This can be done very easily by PHP using a plain simple file, or a
    database.
    If You are new to databases, I advise you to use a plain file, it is much
    easier.

    You just increase the counter every time a visitor calls a page on your
    site.
    This is often done by using a image that calls a PHP-script.

    What about cookies?
    What I describe above is not actually a visitorcounter: It is a
    pagehitcounter.
    If you want to count the number of unique visitors, you could use a cookie
    for that.
    This is how you do that:
    1) If the countscript (possible the one that returns an image) is called, it
    checks for the existance of a certain name set in the cookie.
    eg "visitedalready "
    1a) It is there: do nothing
    1b) It is not there: set it in the cookie, and increase your counter by 1.

    If cookies are disabled you could switch to SESSION-storage of that
    "visitedalready ".
    The advantage is that Session will be build even if cookies are disabled.
    This is done by url-rewriting, something like this:
    phpscript.php?S ESSIONID=asghdf hgasfdghasfdhga sfd

    Hope that helps a bit.

    Regards,
    Erwin Moller

    Comment

    • Ian.H

      #3
      Re: visitor counter using cookie

      On Mon, 09 Aug 2004 05:19:28 -0700, Ben wrote:
      [color=blue]
      > Hi all,
      > This has been asked in the past in different ways. I'm still a bit
      > confused about setting up counters. I'm quite new to php. I've read
      > few tutorials about writing counters using cookie and sessions. It
      > sounds quite straight-forward. But what I'm unsure about is- if the
      > browser is set to accept cookies manually and the user blocks the
      > cookie, what happens? I think in that case, the counter is not
      > incremented because the value is not returned by the browser. Then we
      > are likely to get inaccurate counters. Is there a way to get
      > "accurate" counters?
      >
      > Thanx
      > Ben[/color]


      There's only one "reliable" way Ben, and that's logfile analysis. "Hit
      counters" aren't worth the time they take to code (3 mins?).

      If you have access to access_log, google for Webalizer and AWStats. AWS is
      more complete in its analysis, but both are great tools.

      An example of these 2 tools in action if interested:


      <http://stats.web.digis erv.net/>
      <http://aws.digiserv.ne t/awstats.pl?conf ig=dsrc.digiser v.net>


      HTH =)



      Regards,

      Ian

      --
      Ian.H
      digiServ Network
      London, UK


      Comment

      • John Dunlop

        #4
        Re: visitor counter using cookie

        Ian.H wrote:
        [color=blue]
        > On Mon, 09 Aug 2004 05:19:28 -0700, Ben wrote:[/color]

        [ ... ]
        [color=blue][color=green]
        > > Is there a way to get "accurate" counters?[/color]
        >
        > There's only one "reliable" way Ben, and that's logfile analysis.[/color]

        But don't equate server load with requests. Logfiles
        indicate not requests, but server load. It isn't
        practicable to count requests, nor useful to relay server
        load statistics to end users.

        --
        Jock

        Comment

        • Ian.H

          #5
          Re: visitor counter using cookie

          On Mon, 09 Aug 2004 19:24:23 +0100, John Dunlop wrote:
          [color=blue]
          > Ian.H wrote:
          >[color=green]
          >> On Mon, 09 Aug 2004 05:19:28 -0700, Ben wrote:[/color]
          >
          > [ ... ]
          >[color=green][color=darkred]
          >> > Is there a way to get "accurate" counters?[/color]
          >>
          >> There's only one "reliable" way Ben, and that's logfile analysis.[/color]
          >
          > But don't equate server load with requests. Logfiles
          > indicate not requests, but server load. It isn't
          > practicable to count requests, nor useful to relay server
          > load statistics to end users.[/color]


          You've confused me John.. not requests?

          My apache logs show nothing of server load (unless I tallied up concurrent
          hits for each second of the day and then would be inaccurate.. what
          about other services?).. but they do show requests, beit from a human and
          browser or google etc.

          The OP never mentioned whether this was to be private or publically
          displayed values either.. displaying stupid counters to visitors is an
          annoyance at best (most places that offer counters are also NULL-routed
          here so any visits from myself would once again, cause inaccurate results).



          Regards,

          Ian

          --
          Ian.H
          digiServ Network
          London, UK


          Comment

          • John Dunlop

            #6
            Re: visitor counter using cookie

            Ian.H wrote:
            [color=blue]
            > On Mon, 09 Aug 2004 19:24:23 +0100, John Dunlop wrote:
            >[color=green]
            > > But don't equate server load with requests. Logfiles
            > > indicate not requests, but server load. It isn't
            > > practicable to count requests, nor useful to relay server
            > > load statistics to end users.[/color]
            >
            > You've confused me John..[/color]

            Sorry Ian.
            [color=blue]
            > not requests?[/color]

            Requests don't necessarily reach the origin server, so
            there's no feasible way to count them all. A request for a
            resource might be fulfilled by a cache, whilst the origin
            server is unaware of the transaction.

            Jeffrey P. Goldberg's page on the subject is worth reading:
            <http://www.goldmark.or g/netrants/webstats/>.

            [ ... ]
            [color=blue]
            > displaying stupid counters to visitors is an annoyance at best[/color]

            Agreed; and in Mr. Goldberg's words, 'there are basically
            two ways to put [counters] in your page: the wrong way and
            the very wrong way'.

            [ ... ]

            --
            Jock

            Comment

            • Ian.H

              #7
              Re: visitor counter using cookie

              On Mon, 09 Aug 2004 20:43:17 +0100, John Dunlop wrote:
              [color=blue]
              > Ian.H wrote:
              >[color=green]
              >> On Mon, 09 Aug 2004 19:24:23 +0100, John Dunlop wrote:
              >>[color=darkred]
              >> > But don't equate server load with requests. Logfiles
              >> > indicate not requests, but server load. It isn't
              >> > practicable to count requests, nor useful to relay server
              >> > load statistics to end users.[/color]
              >>
              >> You've confused me John..[/color]
              >
              > Sorry Ian.[/color]


              No probs.. wasn't sure if I was reading things wrong or.... =)

              [color=blue][color=green]
              >> not requests?[/color]
              >
              > Requests don't necessarily reach the origin server, so
              > there's no feasible way to count them all. A request for a
              > resource might be fulfilled by a cache, whilst the origin
              > server is unaware of the transaction.[/color]


              Ahh gotchya! Indeed and good point.

              [color=blue]
              > Jeffrey P. Goldberg's page on the subject is worth reading:
              > <http://www.goldmark.or g/netrants/webstats/>.[/color]


              Bookmarked for later reading =)

              [color=blue]
              >
              > [ ... ]
              >[color=green]
              >> displaying stupid counters to visitors is an annoyance at best[/color]
              >
              > Agreed; and in Mr. Goldberg's words, 'there are basically
              > two ways to put [counters] in your page: the wrong way and
              > the very wrong way'.
              >
              > [ ... ][/color]


              lol! I love it.

              Thanks for the clarification John =)



              Regards,

              Ian

              --
              Ian.H
              digiServ Network
              London, UK


              Comment

              Working...