Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > ASP Page Counter

Reply
Thread Tools

ASP Page Counter

 
 
Paul W Smith
Guest
Posts: n/a
 
      08-15-2008
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("TotalCount")= 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


 
Reply With Quote
 
 
 
 
Paul W Smith
Guest
Posts: n/a
 
      08-15-2008

>> 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!


 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      08-15-2008
Paul W Smith wrote on 15 aug 2008 in
microsoft.public.inetserver.asp.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("TotalCount")= 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)
 
Reply With Quote
 
Daniel Crichton
Guest
Posts: n/a
 
      08-18-2008
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("TotalCount")= 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("TotalCount") 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.Lock
If IsEmpty(Application("TotalHits")) then
Application("TotalHits") = 1
Else
Application("TotalHits") = Applicaton("TotalHits") + 1
End If
Application.Unlock

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_OnStart 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


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      08-18-2008
Daniel Crichton wrote on 18 aug 2008 in
microsoft.public.inetserver.asp.general:

> Application.Lock
> If IsEmpty(Application("TotalHits")) then
> Application("TotalHits") = 1
> Else
> Application("TotalHits") = Applicaton("TotalHits") + 1
> End If
> Application.Unlock
>


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)
 
Reply With Quote
 
Daniel Crichton
Guest
Posts: n/a
 
      08-18-2008
Evertjan. wrote on 18 Aug 2008 15:47:38 GMT:

> Daniel Crichton wrote on 18 aug 2008 in
> microsoft.public.inetserver.asp.general:


>> Application.Lock
>> If IsEmpty(Application("TotalHits")) then
>> Application("TotalHits") = 1
>> Else
>> Application("TotalHits") = Applicaton("TotalHits") + 1
>> End If
>> Application.Unlock



> 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


 
Reply With Quote
 
Anthony Jones
Guest
Posts: n/a
 
      08-20-2008
"Evertjan." <(E-Mail Removed)> wrote in message
news:Xns9AFEB4FBFC4F0eejj99@194.109.133.242...
> Daniel Crichton wrote on 18 aug 2008 in
> microsoft.public.inetserver.asp.general:
>
> > Application.Lock
> > If IsEmpty(Application("TotalHits")) then
> > Application("TotalHits") = 1
> > Else
> > Application("TotalHits") = Applicaton("TotalHits") + 1
> > End If
> > Application.Unlock
> >

>
> 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


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      08-21-2008
Anthony Jones wrote on 20 aug 2008 in
microsoft.public.inetserver.asp.general:

> "Evertjan." <(E-Mail Removed)> wrote in message
> news:Xns9AFEB4FBFC4F0eejj99@194.109.133.242...
>> Daniel Crichton wrote on 18 aug 2008 in
>> microsoft.public.inetserver.asp.general:
>>
>> > Application.Lock
>> > If IsEmpty(Application("TotalHits")) then
>> > Application("TotalHits") = 1
>> > Else
>> > Application("TotalHits") = Applicaton("TotalHits") + 1
>> > End If
>> > Application.Unlock
>> >

>>
>> 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)
 
Reply With Quote
 
Anthony Jones
Guest
Posts: n/a
 
      08-21-2008
"Evertjan." <(E-Mail Removed)> wrote in message
news:Xns9B01B961237E8eejj99@194.109.133.242...
> Anthony Jones wrote on 20 aug 2008 in
> microsoft.public.inetserver.asp.general:
>
> > "Evertjan." <(E-Mail Removed)> wrote in message
> > news:Xns9AFEB4FBFC4F0eejj99@194.109.133.242...
> >> Daniel Crichton wrote on 18 aug 2008 in
> >> microsoft.public.inetserver.asp.general:
> >>
> >> > Application.Lock
> >> > If IsEmpty(Application("TotalHits")) then
> >> > Application("TotalHits") = 1
> >> > Else
> >> > Application("TotalHits") = Applicaton("TotalHits") + 1
> >> > End If
> >> > Application.Unlock
> >> >
> >>
> >> 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


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      08-22-2008
Anthony Jones wrote on 21 aug 2008 in
microsoft.public.inetserver.asp.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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Page File counter and Private Bytes Counter George2 C++ 1 01-31-2008 09:27 AM
Session("counter") vs. ViewState("counter")...a newbie question The Eeediot ASP .Net 3 12-22-2004 09:31 PM
Page Counter Component, ASP 3.0 Roland Ramirez ASP General 3 02-02-2004 07:40 PM
ASP 3.0, Need help with Page Counter Component Roland Ramirez ASP General 1 01-30-2004 06:04 PM
Use a page counter with asp Krechting ASP General 3 01-03-2004 04:44 AM



Advertisments