Total Hits with Text File

On way to track the number of hits that your website receives is by using a text file counter.

To do this, create a text file called /TotalHits.txt and save it within the /includes/ directory.  Then, include the code below at the top of every page you want hits counted from:

<%
Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
HitsFile = Server.MapPath ("/includes") & "\totalhits.txt"
Set InStream= FileObject.OpenTextFile (HitsFile, 1, false )
OldHits = Trim(InStream.ReadLine)
NewHits = OldHits + 1
Set OutStream= FileObject.CreateTextFile (HitsFile, True)
OutStream.WriteLine(NewHits)
%>

That’s it.  Now, you’ve got yourself a Total Hits counter that uses a good old fashioned text file.

< Back to ASP Scripts