|
|
| YOUR HIT COUNTER IN ASP |
|
I will in this tutorial show you how to make a simple hit counter, using a
tetextfile.
|
Making the Hit-counter
|
|
When a user enters your site, you have to update the textfile. I have called
my textfile, mycounter.txt. I first get the current value and then increment this
before I store it. And at the end, I display the viewers that have entered the site.
The code is given below. It is important that you give the textfile write permission.
|
//the filename
dim filename
filename = "mycounter.txt"
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'open the file
Set f=fs.OpenTextFile(Server.MapPath(filename), 1)
content = f.ReadAll
If content = "" Then
content = 0
End If
'close the file
f.Close
content = content + 1
Set f=fs.CreateTextFile(filename,true)
f.write(content)
f.close
'empty the objects
Set f=Nothing
Set fs=Nothing
Response.Write(content)
|
|
Category
|
Programming with ASP
|
|
Author
|
Tommy Johannessen
|
|
|
|