Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

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

Victims of Sandy Hook

Stop the Slaughter of Innocents. Congress is bought and paid for by gun lunatics and gun promotion groups. If you want to live in a safe America, help buy Congress back for America. Send a donation to Mayors Against Illegal Guns, 909 Third Avenue, 15th Floor New York, NY 10022


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