ASP tæller ?
På min side Spaz.dk har jeg en tæller som jeg fandt på ASP.dkProblemet er bare at der er en lille fejl ved den som gør at der engang imellem står 96 97
og hvis man så opdaterer bliver det til det altså 97.
Nogen der ved hvorfor der bliver skrevet 2 tal engang imellem.
Hvis man opdaterer forsvinder det altid og så står der det rigtige tal.
OBS : I de 2 tekstfiler står der kun ipér og selve tallet f.eks 97, så de kan ik være problemet.
Koden er her :
<!--#include virtual="/Stats/counter.txt"-->
<%
' These following is coded by Tony Lorentzen, June 2000
' If you want more information or have some freelance
' assignments please contact me at tony@lorentzen.com
function incrementHits()
' Here we open the counterfile and increment it by one
' and return the new value of the counterfile
Dim txtFile, objStream
counterFil = "/Stats/counter.txt"
Set txtFile = Server.CreateObject("Scripting.FileSystemObject")
Set objStream = txtFile.OpenTextFile(Server.MapPath(counterFil), 1, True)
hits = objStream.ReadLine
hits = hits + 1
Set objStream = txtFile.OpenTextFile(Server.MapPath(counterFil), 2, True)
objStream.WriteLine hits
objStream.Close
Set objStream = Nothing
Set txtFile = Nothing
incrementHits = hits
end function
sub updateHistory()
' Here we insert the users IP number, actual date and time
' into the historyfile
Dim txtFile, objStream
counterFil = "/Stats/history.txt"
Set txtFile = Server.CreateObject("Scripting.FileSystemObject")
Set objStream = txtFile.OpenTextFile(Server.MapPath(counterFil), 8, True)
objStream.WriteLine now() & "|" & Request.ServerVariables("REMOTE_HOST")
Set objStream = Nothing
Set txtFile = Nothing
end sub
function cleanHistory()
' This function reads the historyfile and deletes alle entries that
' are older than 15 minutes. To change the default value change the
' variable called "minLimit". The function then return then value
' of the new historyfile for further processing
dim MyArray
minLimit = 15
historyFil = "/Stats/history.txt"
Set txtFile = Server.CreateObject("Scripting.FileSystemObject")
Set objStream = txtFile.OpenTextFile(Server.MapPath(historyFil), 1, True)
Do While Not objStream.AtEndOfStream
StringFromFile = objStream.Readline
MyArray = split(StringFromFile,"|",-1,1)
if dateDiff("n",MyArray(0),Now()) < minLimit then
newFile = newFile & StringFromFile & vbCrLf
end if
Loop
Set objStream = Nothing
cleanHistory = newFile
Set objStream = txtFile.OpenTextFile(Server.MapPath(historyFil), 2, True)
objStream.Write newfile
objStream.Close
Set objStream = Nothing
end function
' Now - let's test if the users IP number exists in the new historyfile
' and if it doesn't we update the historyfile, increment the counterfile
' and response.write the hitcount.
if inStr(1,cleanHistory(),Request.ServerVariables("REMOTE_HOST")) = 0 then
call updateHistory
Response.write incrementHits()
end if
%>