Web page counters are very popular on the Internet.
The following code will allow you to roll your own counters.
The code is Classic ASP using server side JScript.
This page has been visited <strong><%
var Counter=0;
var fs = Server.CreateObject("Scripting.FileSystemObject");
var FileName = String(Request("Path_Info"));
FileName = FileName.substring(1, 255);
FileName = FileName.replace(/\\/g, " ");
FileName = FileName.replace(/\//g, " ");
FileName = "c:\\Counters\\"+FileName+".txt";
if(fs.FileExists(FileName)) {
ts = fs.OpenTextFile(FileName);
Counter = ts.ReadLine();
Response.Write(Counter);
ts.Close();
}
else Response.Write("0");
ts = fs.CreateTextFile(FileName, true);
ts.WriteLine(++Counter);
ts.Close();
ts = null;
fs = null;
%></strong> times.
As you can see from the code, we are using the FileSystemObject to access and save our counter.
The file name is taken from the current page name, and slashes are replaced with spaces.
In this example, the counters are kept in C:\Counters.
IIS will need appropriate permissions to this directory.
The counter is read into the variable if it exists.
The counter is incremented, and the file is overwritten with the new value.
It's that simple.