sloppycode.net
ASP Visitor counter
A basic ASP visitor counter using a textfile.
Home
›
Code snippets
›
ASP
›
ASP Visitor counter
Way back before Web 2.0 these were really fashionable. Honest guv they were. This is a basic visitor counter for ASP. It saves a number to a textfile, then reads it back. It hasn't been tested for race conditions or any type of scaleability it's as basic as you get.
<% '**************************************** 'First Read counter contents Dim counterObj,readNumber,allNumbers,nChars,x Dim counterFile,imagesDir Dim showCounter ' Change this to the name of your counter file counterFile = "counterfile.txt" ' Change this to the directory where your images are kept. No trailing slash imagesDir = "/images" ' Open the file and get the current counter value, and increment Set counterObj = Server.CreateObject("Scripting.FileSystemObject") Set readNumber = counterObj.OpenTextFile(Server.MapPath(counterFile)) allNumbers = readNumber.ReadLine() readNumber.Close allNumbers = CStr(allNumbers) nChars = Len (allNumbers) ' Extract the numbers Dim chars() ReDim chars(nChars) For x = 1 to nChars chars(x) = Mid(allNumbers,x,1) Next 'allNumbers = CInt(allNumbers) allNumbers = allNumbers + 1 ' Write the file Dim cFile Set cFile = counterObj.CreateTextFile(Server.MapPath(counterFile),True) cFile.WriteLine(allNumbers) cFile.Close ' Turn the counter images into a string For x = 1 to nChars showCounter = showCounter & "<img src=""" & imagesDir & "/" & (chars(x)) & ".gif"">" Next %>
{Name}
Says:
{Date}
{Text}
› Home
› C#
› Snippets
› Articles
› Tools
› Taglines
› ASP
› Dictionary Object
› FSO
› Unix cheat sheet
› Gaming
› CSS
› Yak
› Umbraco
› About
› Contact
› Privacy
› Projects
› Search