Free ASP counter (.asp)
If you need a hit counter for only one file, try this example


The code bellow is prepared to be added to your asp pages and it will automatically start counting hits for the page containning it. You may copy the same code to several ASP pages, and the script will count hits for all pages individually.

You must create a subfolder named "Mycounters" within the cgi-bin directory. The name of the subdirectory may be changed in the script.

The script will atomatically create one counter (one file within subfolder "Mycounters") per each page  containing the script bellow in the first visit. Each time a page is visited the corresponding counter will be open, read the number of hits, increased by one and the new number of hits save to the same counter file.

The name of individual counters within subfolder "Mycounters" will shown the path to the page visited. For example: 
  Hits at /index.asp will  be save to /cgi-bin/mycounters/indexasp.txt
  Hits at /mydir1/page1.asp will  be save to /cgi-bin/mycounters/mydir1page1asp.txt

To get the number of hits in all your pages you may used the script shown in the bottom table.
 

counter.asp
<% 
file=request.servervariables("PATH_INFO")
file = replace(file,"/","")
file = replace(file,".","")
if file="" then
file="otros"
end if

Set fs = CreateObject("Scripting.FileSystemObject")
Wfile=server.mappath("\") & "\cgi-bin\Mycounters\" & file & ".txt"
on error resume next
Set a = fs.OpenTextFile(Wfile)
hits = Clng(a.ReadLine)
hits = hits 1
a.close

if error then
hits = 1
end if

Set a = fs.CreateTextFile(Wfile,True)
a.WriteLine(hits)
a.Close
%>

Number of hits: <% =hits %>

The number of hits in the corresponding counter will be increased each time your page is visited. Last line in this script will allow you to show the number of hits in your response page. 
 

In order to get the number of hits to all pages we may used the script bellow:
 

Showallcounters.asp
<% 
FolderToCheck=server.mappath("\") & "\cgi-bin\Mycounters\"
 

 Dim fs, f, f1, fc, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(FolderToCheck)
 Set fc = f.Files
 

For Each f1 in fc
  Wfile=f1.name
 

  if right(Wfile,4)=".txt" then
   FiletoCheck=FolderToCheck & "\" & Wfile
    Set a=fs.OpenTextFile(FiletoCheck)
     hits=Clng(a.ReadLine) 
      Response.write(Wfile & ": " & hits & "<BR>")
   allhits=allhits hits
end if
 

Next

%>
<HR>
All hits: <% =allhits %>
<BR>
Date: <% =Date %>

 

 

AspTutorial.info.