ASP Page Counter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul W Smith

    ASP Page Counter

    I have written a hit counter, which I believe counts the times my page is
    hit by a user for each unique session by the user.

    The relevant part of my code is below:


    If IsEmpty(Session ("TotalCount ")) Then

    ' Increment or reset the count
    If Weekday(Date(), vbSunday) = 1 And dtDate <Date then
    iCount = 1
    Else
    iCount = iCount + 1
    End If
    dtDate = Date

    End If

    Session("TotalC ount")= iCount

    The page is www.middlesexccl.com


    My issue is I cannot believe the number of hits I am getting - or more
    accurately should I trust the number of hits I am getting.

    When I first go to the URL I see the count increased by one, but it does not
    incredment if I reload the page.

    Is there any techniques that the clubs involved could be using, i.e. some
    sort of 'fancy' linking to the page from their web site which might be
    causing the count to be incremented unduely? I am sorry if that sounds a
    little vague but I cannot udnerstand where the hits are coming from.

    If anyone has any other odeas on how to test this please let me have
    details.

    Many thanks to all those who give this isue their attention.

    Paul Smith


  • McKirahan

    #2
    Re: ASP Page Counter

    "Paul W Smith" <pws@NOSPAM.twe lve.me.ukwrote in message
    news:Oq3L4Us$IH A.2244@TK2MSFTN GP05.phx.gbl...

    [snip]
    My issue is I cannot believe the number of hits I am getting - or more
    accurately should I trust the number of hits I am getting.
    Check your raw Web log files.

    They'll identify the date, time, and ip address of each "hit".

    FTP into your site; if you can't find them then ask your Web host.


    Comment

    • Paul W Smith

      #3
      Re: ASP Page Counter

      >My issue is I cannot believe the number of hits I am getting - or more
      >accurately should I trust the number of hits I am getting.
      >
      Check your raw Web log files.
      >
      They'll identify the date, time, and ip address of each "hit".
      >
      FTP into your site; if you can't find them then ask your Web host.
      Thank for that great advice - found some explainations of web pages on web,
      and after some integration of the log files for the week, I can see that my
      hit count is actually pretty accurate!


      Comment

      • Evertjan.

        #4
        Re: ASP Page Counter

        Paul W Smith wrote on 15 aug 2008 in
        microsoft.publi c.inetserver.as p.general:
        If IsEmpty(Session ("TotalCount ")) Then
        >
        ' Increment or reset the count
        If Weekday(Date(), vbSunday) = 1 And dtDate <Date then
        iCount = 1
        Else
        iCount = iCount + 1
        End If
        dtDate = Date
        >
        End If
        >
        Session("TotalC ount")= iCount
        >
        This will only increment iCount once every session.

        Seems to me the above is not the whole story.

        Please show a minimal working example.

        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress)

        Comment

        • Daniel Crichton

          #5
          Re: ASP Page Counter

          Paul wrote on Fri, 15 Aug 2008 11:53:57 +0100:
          I have written a hit counter, which I believe counts the times my page
          is hit by a user for each unique session by the user.
          The relevant part of my code is below:
          If IsEmpty(Session ("TotalCount ")) Then
          ' Increment or reset the count
          If Weekday(Date(), vbSunday) = 1 And dtDate <Date then iCount
          = 1
          Else iCount = iCount + 1
          End If dtDate = Date
          End If
          Session("TotalC ount")= iCount
          The page is www.middlesexccl.com
          My issue is I cannot believe the number of hits I am getting - or more
          accurately should I trust the number of hits I am getting.
          When I first go to the URL I see the count increased by one, but it
          does not incredment if I reload the page.
          Is there any techniques that the clubs involved could be using, i.e.
          some sort of 'fancy' linking to the page from their web site which
          might be causing the count to be incremented unduely? I am sorry if
          that sounds a little vague but I cannot udnerstand where the hits are
          coming from.
          If anyone has any other odeas on how to test this please let me have
          details.
          Many thanks to all those who give this isue their attention.
          Paul Smith

          The Session object is a per-session object, so you'll only see a TotalCount
          value for your own session. Also, as you only increment if
          Session("TotalC ount") is empty, it will only increment once. Looking at the
          code you posted, there is no way that could be the only code handling the
          counter on that site.

          For a counter that tracks sessions for you site, look into using the
          Application object in the Session_OnStart event in global.asa. This would
          allow you to increment the counter by 1 for each new Session that is
          created, and is visible to any page that can read the Application object.

          For instance, look at this: http://www.asptutorial.info/script/activeuserscounter/

          However, note that this only records the number of active sessions - to get
          the total number of sessions since reset, drop the Session_OnEnd event code.
          If you want actual hits to pages, you will need to add code into every ASP
          page on your site to increment an Application variable, eg.

          Application.Loc k
          If IsEmpty(Applica tion("TotalHits ")) then
          Application("To talHits") = 1
          Else
          Application("To talHits") = Applicaton("Tot alHits") + 1
          End If
          Application.Unl ock

          You could then, if you wanted, display the number of sessions and the number
          of hits as counters on your site. You might want to combine this with the
          Application_OnS tart even in global.asa to initialise the "TotalHits" value,
          then you only need the incrementing line in each page rather than the entire
          If ... End If block.

          Don't forget that the figures will be lost if the IIS process is
          recycled/stopped/started though.

          --
          Dan


          Comment

          • Evertjan.

            #6
            Re: ASP Page Counter

            Daniel Crichton wrote on 18 aug 2008 in
            microsoft.publi c.inetserver.as p.general:
            Application.Loc k
            If IsEmpty(Applica tion("TotalHits ")) then
            Application("To talHits") = 1
            Else
            Application("To talHits") = Applicaton("Tot alHits") + 1
            End If
            Application.Unl ock
            >
            I do not think a lock will be usefull/neccesary for a single statement.
            Don't forget that the figures will be lost if the IIS process is
            recycled/stopped/started though.
            So it is not usefull at all, methinks,
            better use a database or a single file.

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

            The application stored counter could be used for counting the number of
            "active" visitors, since they are zero at a new application start anyway.

            The count up and count down could be put in the global asa session subs.

            Perha[s the OP wanted that.

            --
            Evertjan.
            The Netherlands.
            (Please change the x'es to dots in my emailaddress)

            Comment

            • Daniel Crichton

              #7
              Re: ASP Page Counter

              Evertjan. wrote on 18 Aug 2008 15:47:38 GMT:
              Daniel Crichton wrote on 18 aug 2008 in
              microsoft.publi c.inetserver.as p.general:
              >Application.Lo ck
              >If IsEmpty(Applica tion("TotalHits ")) then
              >Application("T otalHits") = 1
              >Else
              >Application("T otalHits") = Applicaton("Tot alHits") + 1
              >End If
              >Application.Un lock
              I do not think a lock will be usefull/neccesary for a single statement.
              Probably not, but it's been a while since I looked into the effects of
              locking.
              >Don't forget that the figures will be lost if the IIS process is
              >recycled/stopped/started though.
              So it is not usefull at all, methinks, better use a database or a
              single file.
              It's useful if you only need a rough idea of what's going on.
              ---------------
              The application stored counter could be used for counting the number of
              "active" visitors, since they are zero at a new application start
              anyway.
              The count up and count down could be put in the global asa session
              subs.
              Perha[s the OP wanted that.
              Which is what I linked to :)

              --
              Dan


              Comment

              • Anthony Jones

                #8
                Re: ASP Page Counter

                "Evertjan." <exjxw.hannivoo rt@interxnl.net wrote in message
                news:Xns9AFEB4F BFC4F0eejj99@19 4.109.133.242.. .
                Daniel Crichton wrote on 18 aug 2008 in
                microsoft.publi c.inetserver.as p.general:
                >
                Application.Loc k
                If IsEmpty(Applica tion("TotalHits ")) then
                Application("To talHits") = 1
                Else
                Application("To talHits") = Applicaton("Tot alHits") + 1
                End If
                Application.Unl ock
                >
                I do not think a lock will be usefull/neccesary for a single statement.
                >


                Request A arrives
                Request B arrices

                Thread handling A reads Totalhits (its 10)
                Thread handling B reads TotalHits (its still 10)
                Thread handling B assigns 11 to TotalHits
                Thread handling A also assigns 11 to TotalHits

                Technically then the Lock is necessary although in reality it might not
                actually matter.

                --
                Anthony Jones - MVP ASP/ASP.NET


                Comment

                • Evertjan.

                  #9
                  Re: ASP Page Counter

                  Anthony Jones wrote on 20 aug 2008 in
                  microsoft.publi c.inetserver.as p.general:
                  "Evertjan." <exjxw.hannivoo rt@interxnl.net wrote in message
                  news:Xns9AFEB4F BFC4F0eejj99@19 4.109.133.242.. .
                  >Daniel Crichton wrote on 18 aug 2008 in
                  >microsoft.publ ic.inetserver.a sp.general:
                  >>
                  Application.Loc k
                  If IsEmpty(Applica tion("TotalHits ")) then
                  Application("To talHits") = 1
                  Else
                  Application("To talHits") = Applicaton("Tot alHits") + 1
                  End If
                  Application.Unl ock
                  >
                  >>
                  >I do not think a lock will be usefull/neccesary for a single statement.
                  >>
                  >
                  Request A arrives
                  Request B arrices
                  >
                  Thread handling A reads Totalhits (its 10)
                  Thread handling B reads TotalHits (its still 10)
                  Thread handling B assigns 11 to TotalHits
                  Thread handling A also assigns 11 to TotalHits
                  >
                  Technically then the Lock is necessary although in reality it might not
                  actually matter.
                  That could be true, but it also could be,
                  that ASP in singlethreaded on a per statement basis.


                  --
                  Evertjan.
                  The Netherlands.
                  (Please change the x'es to dots in my emailaddress)

                  Comment

                  • Anthony Jones

                    #10
                    Re: ASP Page Counter

                    "Evertjan." <exjxw.hannivoo rt@interxnl.net wrote in message
                    news:Xns9B01B96 1237E8eejj99@19 4.109.133.242.. .
                    Anthony Jones wrote on 20 aug 2008 in
                    microsoft.publi c.inetserver.as p.general:
                    >
                    "Evertjan." <exjxw.hannivoo rt@interxnl.net wrote in message
                    news:Xns9AFEB4F BFC4F0eejj99@19 4.109.133.242.. .
                    Daniel Crichton wrote on 18 aug 2008 in
                    microsoft.publi c.inetserver.as p.general:
                    >
                    Application.Loc k
                    If IsEmpty(Applica tion("TotalHits ")) then
                    Application("To talHits") = 1
                    Else
                    Application("To talHits") = Applicaton("Tot alHits") + 1
                    End If
                    Application.Unl ock

                    >
                    I do not think a lock will be usefull/neccesary for a single statement.
                    >
                    Request A arrives
                    Request B arrices

                    Thread handling A reads Totalhits (its 10)
                    Thread handling B reads TotalHits (its still 10)
                    Thread handling B assigns 11 to TotalHits
                    Thread handling A also assigns 11 to TotalHits

                    Technically then the Lock is necessary although in reality it might not
                    actually matter.
                    >
                    That could be true, but it also could be,
                    that ASP in singlethreaded on a per statement basis.
                    >
                    The only time that would be true is if the whole site is single threaded due
                    to debugging being enabled.


                    --
                    Anthony Jones - MVP ASP/ASP.NET


                    Comment

                    • Evertjan.

                      #11
                      Re: ASP Page Counter

                      Anthony Jones wrote on 21 aug 2008 in
                      microsoft.publi c.inetserver.as p.general:
                      Technically then the Lock is necessary although in reality it might
                      not actually matter.
                      >That could be true, but it also could be,
                      >that ASP in singlethreaded on a per statement basis.
                      The only time that would be true is if the whole site is single
                      threaded due to debugging being enabled.
                      Why?

                      There is no advantage to multithread a single "let" statement,
                      and in global.asa it even is detrimental.
                      So it is just the choice of the VBS interpreter programmer.

                      Do we know, or can we test this?

                      --
                      Evertjan.
                      The Netherlands.
                      (Please change the x'es to dots in my emailaddress)

                      Comment

                      • Anthony Jones

                        #12
                        Re: ASP Page Counter

                        "Evertjan." <exjxw.hannivoo rt@interxnl.net wrote in message
                        news:Xns9B02A9E 6BABE6eejj99@19 4.109.133.242.. .
                        Anthony Jones wrote on 21 aug 2008 in
                        microsoft.publi c.inetserver.as p.general:
                        >
                        Technically then the Lock is necessary although in reality it might
                        not actually matter.
                        >
                        That could be true, but it also could be,
                        that ASP in singlethreaded on a per statement basis.
                        >
                        The only time that would be true is if the whole site is single
                        threaded due to debugging being enabled.
                        >
                        Why?
                        >
                        There is no advantage to multithread a single "let" statement,
                        and in global.asa it even is detrimental.
                        So it is just the choice of the VBS interpreter programmer.
                        >
                        Do we know, or can we test this?
                        >
                        I don't think you've quite grasped the concept yet.

                        Let me step you through my earlier example more slowly (to keep things
                        simple I'll assume one cpu)

                        Request A arrives
                        ASP takes a session object matching the Session cookie
                        ASP takes an existing scripting context not currently in use
                        ASP takes the script that the path indicates
                        ASP takes an idle thread from a thread pool (we'll give this thread an
                        ID of 1)
                        ASP puts this lot together and starts executing the script on thread 1

                        Request B arrives

                        ASP takes a session object matching the Session cookie
                        ASP takes an existing scripting context not currently in use
                        ASP takes the script that the path indicates
                        ASP takes an idle thread from a thread pool (we'll give this thread an
                        ID of 2)
                        ASP puts this lot together and starts executing the script on thread 2


                        Thread 1 handling A reads Totalhits (its 10)
                        Dispite what may seem the line:-
                        Application("To talHits") = Applicaton("Tot alHits") + 1
                        is not a single atomic operation
                        There is a read, there is an add and there is a write (with plenty in
                        between)
                        all of which may be pre-empted at any time.
                        At this point thread 1 has merely read the value then its pre-empted
                        and the scheduler starts executing Thread 2

                        Thread 2 handling B reads TotalHits (its still 10)
                        Here thread 2 has read the same value neither thread has written yet.
                        Hence it has read the same value

                        Thread 2 handling B assigns 11 to TotalHits
                        The addition is performed and the value written back to the application
                        object
                        Thread 2 completes in the knowledge of a job well done.

                        Thread 1 handling A also assigns 11 to TotalHits
                        Thread 1 resumes where it left off
                        It has just read the value it has no idea that it has changed since
                        It performs the addition and writes the value 11 back to the application
                        Thread 2 complete in the knowledge of a job well done.

                        Do you see it now?


                        --
                        Anthony Jones - MVP ASP/ASP.NET


                        Comment

                        • Evertjan.

                          #13
                          Re: ASP Page Counter

                          Anthony Jones wrote on 22 aug 2008 in
                          microsoft.publi c.inetserver.as p.general:
                          Thread 1 handling A reads Totalhits (its 10)
                          Dispite what may seem the line:-
                          Application("To talHits") = Applicaton("Tot alHits") + 1
                          is not a single atomic operation
                          There is a read, there is an add and there is a write (with plenty in
                          between)
                          all of which may be pre-empted at any time.
                          At this point thread 1 has merely read the value then its pre-empted
                          and the scheduler starts executing Thread 2
                          [ etc ]


                          You are so wrong in thinking,
                          that because it is logical,
                          it is implemented that way.

                          While it could very well be the case,
                          the logic does not prove the factual implementation.

                          Ony the source code or the testing can prove it.

                          --
                          Evertjan.
                          The Netherlands.
                          (Please change the x'es to dots in my emailaddress)

                          Comment

                          • Anthony Jones

                            #14
                            Re: ASP Page Counter

                            "Evertjan." <exjxw.hannivoo rt@interxnl.net wrote in message
                            news:Xns9B02BC4 967123eejj99@19 4.109.133.242.. .
                            Anthony Jones wrote on 22 aug 2008 in
                            microsoft.publi c.inetserver.as p.general:
                            >
                            Thread 1 handling A reads Totalhits (its 10)
                            Dispite what may seem the line:-
                            Application("To talHits") = Applicaton("Tot alHits") + 1
                            is not a single atomic operation
                            There is a read, there is an add and there is a write (with plenty
                            in
                            between)
                            all of which may be pre-empted at any time.
                            At this point thread 1 has merely read the value then its pre-empted
                            and the scheduler starts executing Thread 2
                            [ etc ]
                            >
                            >
                            You are so wrong in thinking,
                            that because it is logical,
                            it is implemented that way.
                            >
                            While it could very well be the case,
                            the logic does not prove the factual implementation.
                            >
                            Ony the source code or the testing can prove it.

                            Here is a fact the VBScript engine has no idea what an application object
                            is.

                            Here is another fact VBScript does not compile to native code.

                            Here is another fact VBScript doesn't create a zillion critical sections
                            around simple assignment statements.

                            You can lead a horse to water but you can't make it drink.


                            --
                            Anthony Jones - MVP ASP/ASP.NET


                            Comment

                            • Evertjan.

                              #15
                              Re: ASP Page Counter

                              Anthony Jones wrote on 22 aug 2008 in
                              microsoft.publi c.inetserver.as p.general:
                              Here is a fact the VBScript engine has no idea what an application object
                              is.
                              >
                              Here is another fact VBScript does not compile to native code.
                              >
                              Here is another fact VBScript doesn't create a zillion critical sections
                              around simple assignment statements.
                              >
                              You can lead a horse to water but you can't make it drink.
                              >
                              All these things are circumstancial,
                              and do not prove a thing.

                              It still might be that a let statement in global.asa is internally
                              singlethreaded, because it was felt convenient.

                              --
                              Evertjan.
                              The Netherlands.
                              (Please change the x'es to dots in my emailaddress)

                              Comment

                              Working...