Get the ASP Developers widget and many other great free widgets at Widgetbox! ASP Developers: Want to track usage of a website...

Wednesday, May 30, 2007

Want to track usage of a website...

There is anumber of ways to track usage of a website. The easiest way is a hit counter. The follwoing code gives the simplest hit counters. A text document (count.txt) is placed in the same directory (providing that directory has write access) as the page we want the counter to appear on.

<%
on error resume next
set fs = createobject("scripting.filesystemobject")
set ac = fs.opentextfile(server.mappath("count.txt"))
counter = clng(ac.readline)
counter = counter + 1
ac.close
Set ac = fs.CreateTextFile(server.mappath("count.txt"), true)
ac.WriteLine(counter)
ac.Close
Response.Write counter
%>

0 Comments: