I have a few sites that use very simple coldfusion hit counters. Every so often though, the file that holds the number of hits will get filled up with html or other stuff that shouldn't be in there, causing an error. I can't for the life of me figure out why it does this. Below is my code, if anyone has any suggestions, I'll be eternally grateful.
<!--- Set directory path for hits file --->
<cfset hitsfile=ExpandPath("sitehits.txt"
>
<!--- Read hits from hits file --->
<cffile action="Read" file=#hitsfile# variable="sitehits">
<cfif IsDefined("cookie.counted"
is False>
<!--- If cookie is not found, accumulate hits, update file --->
<cfset sitehits=#sitehits# + 1>
<cfif #IsNumeric(sitehits)#>
<cffile action="Write" file=#hitsfile# output=#sitehits#>
</cfif>
<cfcookie name="counted">
</cfif>
<!--- Display hits --->
<cfoutput>#sitehits#</cfoutput>
<!--- Set directory path for hits file --->
<cfset hitsfile=ExpandPath("sitehits.txt"

<!--- Read hits from hits file --->
<cffile action="Read" file=#hitsfile# variable="sitehits">
<cfif IsDefined("cookie.counted"

<!--- If cookie is not found, accumulate hits, update file --->
<cfset sitehits=#sitehits# + 1>
<cfif #IsNumeric(sitehits)#>
<cffile action="Write" file=#hitsfile# output=#sitehits#>
</cfif>
<cfcookie name="counted">
</cfif>
<!--- Display hits --->
<cfoutput>#sitehits#</cfoutput>