Welcome to Bucaro TecHelp!

Bucaro TecHelp
HTTPS Encryption not required because no account numbers or
personal information is ever requested or accepted by this site

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Simplest ASP Code to Track Visits to a Specific Page

You can get just about any information you desire about a page or an entire website from your server log. But if you just want to know how many visits to a specific page, it would be much easier if you could have that specific information available on that page. In this article I give you the simplest ASP code to do just that.

Paste the code shown below at the bottom of you ASP page. Actually you can paste it anywhere on the page that you want the count displayed.

<%
Dim strUnique
strUnique = "count"
Application.Lock
If isEmpty(Application(strUnique)) Then
   Application(strUnique) = "0"
End If
Application(strUnique) = Application(strUnique) + 1
Application.Unlock
%>
User Count <%= Application(strUnique) %>

The code starts by declaring a variable and initializing it with a unique string. Because all ASP application variables are stored in the same memory space, you'll need a different unique string for each page.

Next it uses Application.Lock to prevent multiple page accesses from attempting to update the variable's value at the same time. The If End IF statement checks to see if this is the first time the variable has been accessed, if so, it initializes the variable's value to 0. It then increments the variable's value by 1.

It then uses Application.Unlock to allow other code to access the variable. It then displays the value contained in the variable. Now to know how many visits to the page, you just have to visit the page and read the count.

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro

Fire HD
[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2010 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269