ASP - Hit Counter (Read/Write to text file)
Key Points
- Open file and read total hits
- Add one to counter
- Send counter info to browser
- Open file and write new total
- Hit REFRESH or RELOAD to increment
CODE:
<%
'Open file, read value & close
set fso = createobject("scripting.filesystemobject")
set act = fso.opentextfile(server.mappath("HitCounter.txt"))
counter = clng(act.readline)
act.close
'Add one to counter variable
counter = counter + 1
'Send counter info to browser
Response.Write "<font color=red size=5><b>You are visitor Number " & counter & "</b></font>"
'Open file, write new counter value & close
set act = fso.CreateTextFile(server.mappath("HitCounter.txt"),true)
act.WriteLine(counter)
act.Close
%>
RESULT:
You are visitor Number 762