Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hit Counter

Status
Not open for further replies.
May 9, 2000
446
GB
Hi, I'm using the global.asa to provide a hit counter, anyway I need to store the actual number in a txt file as the counter keeps resetting! The code i'm using is below can anyone help me out with the storing in a text file bit???

Cheers

(code taken from somewhere but can't remember where!)
<SCRIPT RUNAT=&quot;Server&quot; LANGUAGE=&quot;VBScript&quot;>


sub Session_OnStart
'Lock the Application for concurrency issues
Application.Lock

'Increment the counter
Application(&quot;Hits&quot;) = Application(&quot;Hits&quot;) + 1

'Unlock the Application
Application.UnLock
end sub


sub Application_OnStart
'This variable Hits will store the # of visitors
Application(&quot;Hits&quot;) = 0

'From the date stored in AsOfDate...
Application(&quot;AsOfDate&quot;) = Date
end sub

</SCRIPT>
 
I wouldn't do this in the global if you are writing to a text file. just create a script and call it counter.asp or something. then call the script with a server.execute

here's a sample
'open a text document and read the top line for
'the current hit count
set fso = createobject(&quot;scripting.filesystemobject&quot;)
set act = fso.opentextfile(server.mappath(&quot;count.txt&quot;))
counter = clng(act.readline)
'add one to the current count
counter = counter + 1
act.close

'write new hit count
Set act = fso.CreateTextFile(server.mappath(&quot;count.txt&quot;), true)
act.writeline(counter)
act.close

and there you have a hit counter :)

note: not sure what you have there for the application method, but that method is fairly simple and straight forward. if you still want to go that route you do not nee to use a txt file.
check here
_______________________________________________
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }

_______________________________________________
for the best results to your questions: FAQ333-2924

 
one other note on this. the directory that the .txt resides must have write permissions set. hope it goes smoooothly _______________________________________________
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }

_______________________________________________
for the best results to your questions: FAQ333-2924

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top