incredibly simple asp hit counter tweak required!

liunx

Guest
Ok I have the below script and it's incrementing hits each day to a different text file - as we have several of these scripts all over the site for different pages, it will very quickly become cluttered as a new file is created each day!

Before you say it, I can't use a database of any sort (not even access), but text files are allowed.

So I'm thinking if I could change the below script so it puts all the values into the same text file rather than multiple files, then it'd work nicely.

If the text file produced a delimited list like this, it'd work perfectly!
01/01/2007 - 123;
02/01/2007 - 153;
03/01/2007 - 173;
etc..

can any clever bod solve this?

<html>
<title>Daily Hit Counter</title>
<body bgcolor="#FFFFFF">

<%
on error resume next

' Create a server object
set fso = createobject("scripting.filesystemobject")

' Target the text file to be read.
' The text file is continually updated with the current date from the server
set act = fso.opentextfile(server.mappath("daily_count-"& month(date()) & day(date()) & year(date())&".txt"))

' Read the value contained in the current day hit counter
' If there is no file for the current day the on error resume next command above
' will force the program to the next line
counter = clng(act.readline)

' Add one to the counter. If there was no value the counter will be set to a value of one
counter = counter + 1

' Close the text object.
act.close

' Create a new text file on the server with the current date as part of the name
Set act = fso.createtextfile(server.mappath("daily_count-"& month(date()) & day(date()) & year(date())&".txt"), true)

' Write the counter value to the text object
act.writeline(counter)

' Close the text object
act.Close

'Write out the date and total hits for the current day
%>
<%= counter %> Total Hits for <%= date() %>

</body>
</html>why not just use logparser 2.2 from the Windows 2003 SDK to parse the file and get the count...?
 
Back
Top