Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Count number of visitors for a single ASP page

Hi,
I am looking for a way to count the number of visitors that visit a single
ASP page on a website. Potentially, I'd like to block the ASP page if the
number of visitors exceeding the limit. If you have done this before or know
a way how to do this, I'd really appreciate your help.

Thanks in advance,
Katie
[348 byte] By [Katie] at [2007-11-9 17:45:29]
# 1 Re: Count number of visitors for a single ASP page
I've used an include file in the past and put it on all the pages that I wanted
to have a track of... In the include file I made a connection to a dabase
table. In the table I had a visitor count and the page that was being visited(Using
server.variables for the page name). The pseudo code looked something like
1) Get connection to db
2) Get Server Variable Page name
3) Check to see if page name existed in database
4) if existed, add 1 to count, if not add record to table
5) Set pageHits Variable to value of page hits
6) Display pageHits Variable at bottom of page

In your case this would work as well. If you want to stop loading the page
at a certain value just use the pageHits variable as a BIG if statement around
the enitre asp page after the include file. If you actually want the syntax
I may be able to dig it up, but it was something I wrote about 2 years ago.

Hope This helped,
Q*Bert
@#*^@#

"Katie" <KWorkman@yahoo.com> wrote:
>
>Hi,
>I am looking for a way to count the number of visitors that visit a single
>ASP page on a website. Potentially, I'd like to block the ASP page if the
>number of visitors exceeding the limit. If you have done this before or
know
>a way how to do this, I'd really appreciate your help.
>
>Thanks in advance,
>Katie
Q*bert at 2007-11-11 23:18:11 >
# 2 Re: Count number of visitors for a single ASP page
Thank you for the suggestion!
I can understand what you're talking about, but I am still figuring out a
way to start the process. If it's not too much trouble, I'd very much like
to see how you do it (perhaps some code).

Katie

"Q*bert" <luke_davis_76@hotmail.com> wrote:
>
>I've used an include file in the past and put it on all the pages that I
wanted
>to have a track of... In the include file I made a connection to a dabase
>table. In the table I had a visitor count and the page that was being visited(Using
>server.variables for the page name). The pseudo code looked something like
>1) Get connection to db
>2) Get Server Variable Page name
>3) Check to see if page name existed in database
>4) if existed, add 1 to count, if not add record to table
>5) Set pageHits Variable to value of page hits
>6) Display pageHits Variable at bottom of page
>
>In your case this would work as well. If you want to stop loading the page
>at a certain value just use the pageHits variable as a BIG if statement
around
>the enitre asp page after the include file. If you actually want the syntax
>I may be able to dig it up, but it was something I wrote about 2 years ago.
>
>Hope This helped,
>Q*Bert
>@#*^@#
>
>"Katie" <KWorkman@yahoo.com> wrote:
>>
>>Hi,
>>I am looking for a way to count the number of visitors that visit a single
>>ASP page on a website. Potentially, I'd like to block the ASP page if the
>>number of visitors exceeding the limit. If you have done this before or
>know
>>a way how to do this, I'd really appreciate your help.
>>
>>Thanks in advance,
>>Katie
>
Katie at 2007-11-11 23:19:16 >
# 3 Re: Count number of visitors for a single ASP page
By the way, how do you use the Server Variable Page name? :-)

"Katie" <KWorkman@yahoo.com> wrote:
>
>Thank you for the suggestion!
>I can understand what you're talking about, but I am still figuring out
a
>way to start the process. If it's not too much trouble, I'd very much like
>to see how you do it (perhaps some code).
>
>Katie
>
>
>"Q*bert" <luke_davis_76@hotmail.com> wrote:
>>
>>I've used an include file in the past and put it on all the pages that
I
>wanted
>>to have a track of... In the include file I made a connection to a dabase
>>table. In the table I had a visitor count and the page that was being
visited(Using
>>server.variables for the page name). The pseudo code looked something
like
>>1) Get connection to db
>>2) Get Server Variable Page name
>>3) Check to see if page name existed in database
>>4) if existed, add 1 to count, if not add record to table
>>5) Set pageHits Variable to value of page hits
>>6) Display pageHits Variable at bottom of page
>>
>>In your case this would work as well. If you want to stop loading the
page
>>at a certain value just use the pageHits variable as a BIG if statement
>around
>>the enitre asp page after the include file. If you actually want the syntax
>>I may be able to dig it up, but it was something I wrote about 2 years
ago.
>>
>>Hope This helped,
>>Q*Bert
>>@#*^@#
>>
>>"Katie" <KWorkman@yahoo.com> wrote:
>>>
>>>Hi,
>>>I am looking for a way to count the number of visitors that visit a single
>>>ASP page on a website. Potentially, I'd like to block the ASP page if
the
>>>number of visitors exceeding the limit. If you have done this before or
>>know
>>>a way how to do this, I'd really appreciate your help.
>>>
>>>Thanks in advance,
>>>Katie
>>
>
katie at 2007-11-11 23:20:15 >
# 4 Re: Count number of visitors for a single ASP page
>> By the way, how do you use the Server Variable Page name? :-)<<

Dim strFullPath
strFullPath = Request.ServerVariables("Path_Info")
Response.Write strFullPath

Andrew
Andrew at 2007-11-11 23:21:16 >
# 5 Re: Count number of visitors for a single ASP page
Sorry for the late response, It took me awhile to track this down...

The attached code was in a file called footer.asp. This file was then included
in the pages where I wanted to track visitor counts
NPCAccess.getrs is a function in a differnet page that will return a populated
rs object from a specific database when called.

<b>Visitor Count:</b>

<%set rs = server.CreateObject("ADODB.recordset")

'Update record and set session var so not to count again
if not Session(Request.ServerVariables("PATH_TRANSLATED")) then
SSQL = "Select count(*) as cnt from tblVisitorCount
where path = '" & Request.ServerVariables("Path_Translated") & "'"
cmd.commandtext = SSQL
NPCAccess.getrs SSQL, rs

if rs.Fields("cnt") > 0 then

SSQL = "UPDATE tblVisitorCount SET tblVisitorCount.VisitorCnt =
[tblVisitorCount].[visitorcnt]+1 "
SSQL = SSQL & "WHERE (((tblVisitorCount.Path)='"&Request.ServerVariables
("PATH_TRANSLATED") & "'));"

else
SSQL = "INSERT into tblVisitorCount (VisitorCnt, Path) VALUES (1,"
SSQL = SSQL & "'" & Request.ServerVariables("Path_Translated")
& "')"

end if
cmd.CommandText = SSQL
rs.Close
NPCACCESS.getrs SSQL, rs
session(Request.ServerVariables("PATH_TRANSLATED")) = True
end if

SSQL = "Select visitorcnt from tblVisitorCount where path = '" & Request.ServerVariables("Path_Translated")
& "'"
cmd.CommandText = SSQL
NPCAccess.GetRS SSQL, rs

if not rs.EOF then
Response.Write(rs.Fields("visitorcnt"))
else
Response.Write("Error Retreving Visitor Count Data")
end if

rs.Close
NPCAccess.close
set rs = nothing
set NPCAccess = nothing
set cmd = nothing

Function ShowFileInfo(filespec)
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
ShowFileInfo = " " & FormatDateTIme(f.DateLastModified,vbShortDate)
End Function

%>
"katie" <kvworkman@yahoo.com> wrote:
>
>By the way, how do you use the Server Variable Page name? :-)
>
>"Katie" <KWorkman@yahoo.com> wrote:
>>
>>Thank you for the suggestion!
>>I can understand what you're talking about, but I am still figuring out
>a
>>way to start the process. If it's not too much trouble, I'd very much like
>>to see how you do it (perhaps some code).
>>
>>Katie
>>
>>
>>"Q*bert" <luke_davis_76@hotmail.com> wrote:
>>>
>>>I've used an include file in the past and put it on all the pages that
>I
>>wanted
>>>to have a track of... In the include file I made a connection to a dabase
>>>table. In the table I had a visitor count and the page that was being
>visited(Using
>>>server.variables for the page name). The pseudo code looked something
>like
>>>1) Get connection to db
>>>2) Get Server Variable Page name
>>>3) Check to see if page name existed in database
>>>4) if existed, add 1 to count, if not add record to table
>>>5) Set pageHits Variable to value of page hits
>>>6) Display pageHits Variable at bottom of page
>>>
>>>In your case this would work as well. If you want to stop loading the
>page
>>>at a certain value just use the pageHits variable as a BIG if statement
>>around
>>>the enitre asp page after the include file. If you actually want the
syntax
>>>I may be able to dig it up, but it was something I wrote about 2 years
>ago.
>>>
>>>Hope This helped,
>>>Q*Bert
>>>@#*^@#
>>>
>>>"Katie" <KWorkman@yahoo.com> wrote:
>>>>
>>>>Hi,
>>>>I am looking for a way to count the number of visitors that visit a single
>>>>ASP page on a website. Potentially, I'd like to block the ASP page if
>the
>>>>number of visitors exceeding the limit. If you have done this before
or
>>>know
>>>>a way how to do this, I'd really appreciate your help.
>>>>
>>>>Thanks in advance,
>>>>Katie
>>>
>>
>
Q*bert at 2007-11-11 23:22:15 >
# 6 Re: Count number of visitors for a single ASP page
Thanks, your code really helped.

"Q*bert" <luke_davis_76@hotmail.com> wrote:
>
>Sorry for the late response, It took me awhile to track this down...
>
>The attached code was in a file called footer.asp. This file was then included
>in the pages where I wanted to track visitor counts
>NPCAccess.getrs is a function in a differnet page that will return a populated
>rs object from a specific database when called.
>
><b>Visitor Count:</b>
>
><%set rs = server.CreateObject("ADODB.recordset")
>
>'Update record and set session var so not to count again
>if not Session(Request.ServerVariables("PATH_TRANSLATED")) then
> SSQL = "Select count(*) as cnt from tblVisitorCount
> where path = '" & Request.ServerVariables("Path_Translated") & "'"
> cmd.commandtext = SSQL
> NPCAccess.getrs SSQL, rs
>
>if rs.Fields("cnt") > 0 then
>
> SSQL = "UPDATE tblVisitorCount SET tblVisitorCount.VisitorCnt =
> [tblVisitorCount].[visitorcnt]+1 "
> SSQL = SSQL & "WHERE (((tblVisitorCount.Path)='"&Request.ServerVariables
> ("PATH_TRANSLATED") & "'));"
>
>else
> SSQL = "INSERT into tblVisitorCount (VisitorCnt, Path) VALUES (1,"
> SSQL = SSQL & "'" & Request.ServerVariables("Path_Translated")
> & "')"
>
>end if
> cmd.CommandText = SSQL
> rs.Close
> NPCACCESS.getrs SSQL, rs
> session(Request.ServerVariables("PATH_TRANSLATED")) = True
>end if
>
>SSQL = "Select visitorcnt from tblVisitorCount where path = '" & Request.ServerVariables("Path_Translated")
>& "'"
>cmd.CommandText = SSQL
>NPCAccess.GetRS SSQL, rs
>
>if not rs.EOF then
> Response.Write(rs.Fields("visitorcnt"))
>else
> Response.Write("Error Retreving Visitor Count Data")
>end if
>
>rs.Close
>NPCAccess.close
>set rs = nothing
>set NPCAccess = nothing
>set cmd = nothing
>
>Function ShowFileInfo(filespec)
> Dim fso, f
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set f = fso.GetFile(filespec)
> ShowFileInfo = " " & FormatDateTIme(f.DateLastModified,vbShortDate)
>End Function
>
>%>
>"katie" <kvworkman@yahoo.com> wrote:
>>
>>By the way, how do you use the Server Variable Page name? :-)
>>
>>"Katie" <KWorkman@yahoo.com> wrote:
>>>
>>>Thank you for the suggestion!
>>>I can understand what you're talking about, but I am still figuring out
>>a
>>>way to start the process. If it's not too much trouble, I'd very much
like
>>>to see how you do it (perhaps some code).
>>>
>>>Katie
>>>
>>>
>>>"Q*bert" <luke_davis_76@hotmail.com> wrote:
>>>>
>>>>I've used an include file in the past and put it on all the pages that
>>I
>>>wanted
>>>>to have a track of... In the include file I made a connection to a dabase
>>>>table. In the table I had a visitor count and the page that was being
>>visited(Using
>>>>server.variables for the page name). The pseudo code looked something
>>like
>>>>1) Get connection to db
>>>>2) Get Server Variable Page name
>>>>3) Check to see if page name existed in database
>>>>4) if existed, add 1 to count, if not add record to table
>>>>5) Set pageHits Variable to value of page hits
>>>>6) Display pageHits Variable at bottom of page
>>>>
>>>>In your case this would work as well. If you want to stop loading the
>>page
>>>>at a certain value just use the pageHits variable as a BIG if statement
>>>around
>>>>the enitre asp page after the include file. If you actually want the
>syntax
>>>>I may be able to dig it up, but it was something I wrote about 2 years
>>ago.
>>>>
>>>>Hope This helped,
>>>>Q*Bert
>>>>@#*^@#
>>>>
>>>>"Katie" <KWorkman@yahoo.com> wrote:
>>>>>
>>>>>Hi,
>>>>>I am looking for a way to count the number of visitors that visit a
single
>>>>>ASP page on a website. Potentially, I'd like to block the ASP page if
>>the
>>>>>number of visitors exceeding the limit. If you have done this before
>or
>>>>know
>>>>>a way how to do this, I'd really appreciate your help.
>>>>>
>>>>>Thanks in advance,
>>>>>Katie
>>>>
>>>
>>
>
Katie at 2007-11-11 23:23:19 >