ASP Hit Counter

There are many ways to track usage of a website. The simplest way is with a hit counter. The code provided below is one of the simplest hit counters that can be made in .asp. A text document (count.txt) is placed in the same directory (providing that directory has write access, you may need to place the .txt document in your cgi-bin depending on your provider) as the page we want the counter to appear on. The .txt file is first read to gain the value of the last hit count, one is added to that number, written to the .txt document, closed and the counter value is written as text to the page.

<%
on error resume next 

' Create a server object
set fso = createobject("scripting.filesystemobject")

' Target the text file to be opened
set act = fso.opentextfile(server.mappath("count.txt"))

' Read the value of the text document
' If the text document does not exist then the on error resume next
' will drop down to the next line
counter = clng(act.readline)

' Add one to the counter
counter = counter + 1

' Close the object
act.close

' Create a new text file on the server
Set act = fso.CreateTextFile(server.mappath("count.txt"), true)

' Write the current counter value to the text document
act.WriteLine(counter)

' Close the object
act.Close

' Write the counter to the browser as text
Response.Write counter
%>


ASP Hits FSO hit counter


Back To Top
© 1998 - 2024 psacake.com
Version 7.21 | Advertise on this site