View Full Version : How to make vistor counter

02-17-2003, 08:13 PM
I want to make a vistor counter in asp language...

02-17-2003, 09:29 PM
Do a search through this forum, theres a lot of good examples using databases & text files.

02-18-2003, 01:37 AM
Here's a very simple one that uses FileSystemObject to write to a text file, that won't be incremented upon refresh (since it uses a session variable). It also creates the text file if it doesn't exist:


Dim cfs, cf, thefile, counter, sMapPath
sMapPath = Server.MapPath("\")
thefile = Mid(sMapPath, 1, InStrRev(sMapPath,"\")-1) & "\database\counter.txt"
Set cfs = CreateObject("Scripting.FileSystemObject")
If cfs.FileExists(thefile) Then
Set cf = cfs.OpenTextFile(thefile, 1)
counter = cf.ReadLine
End If
Set cf = cfs.OpenTextFile(thefile, 2, True)
If Session("counted") <> "1" Then counter = counter + 1
Set cf = Nothing
Set cfs = Nothing
Session("counted") = "1"

If you search with some diligence there are many other solutions here as well, I use a counter/logging script with an Access database on my website (I don't display any count on the page though) which keeps track of much more information in an access database (even whether or not users have javascript enabled - although from what I've gathered out of the statistics that really isn't of much use).