This example is a simple text based counter. I call it simple because it will only show page views, not actual
visitors. It uses the File Scripting Object to interact with a text file. The
first thing it does is read the current number in the file and add one to it,
then displays it as text on the page.
<%
'here we set up a connection to the txt file using a physical path
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile("C:\InetPub\wwwroot\counter\count.txt")
'now we read the number in the file
oldNum = CLng(oFile.ReadLine)
'and we close
oFile.Close
'we add one to the number
oldNum = oldNum + 1
'we open the file to overwrite the new number to it
Set oFile = oFSO.OpenTextFile("C:\InetPub\wwwroot\counter\count.txt",2,true)
'and we overwrite it here
oFile.WriteLine(oldNum)
'and we close the file again
oFile.Close
'now we use the number for our display
strCount = oldNum
%>
Below is a mix of html and vbscript. I will display the
script in red to make it more discernable.
That's really all there is to it. The only thing left to
do is create a text file named count.txt and place it in a
directory named counter. Add your numbers to the web and you're all set!