Click here to Skip to main content
16,005,467 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i have a hit counter for a website hosted on our server. i am using vb script to write to text file each time the website has a hit. it is a local website hosted using iis. the problem is that it only writes the hits to the textfile when the website is opened from the server's brower. if the website is opened on another computer, it does not write hits to the text file. I have granted iis permissions to the text file which is on a shared drive.

XML
<font color="#FFFFFF"><b>Total Site Hits:</b>
<SCRIPT type=text/vbscript>
Dim fso
Dim tso
Dim filObject
Dim VisitorCount
Dim strOutputName
Dim objOutputFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set filObject = fso.GetFile("\\cci-opsweb01\TTHitCount\HitCounter.txt")
Set tso = filObject.OpenAsTextStream
VisitorCount = CLng(tso.ReadAll)
VisitorCount = VisitorCount + 1
strOutputName = "\\cci-opsweb01\TTHitCount\HitCounter.txt"
Set objOutputFile = fso.createTextFile(strOutputName,True)
objOutputFile.WriteLine VisitorCount
Document.Write(VisitorCount)
</Script>
Posted
Comments
Ali Reza Barkhordari 22-Apr-13 8:52am    
hit count should be implemented in server side not client side !
StianSandberg 22-Apr-13 17:27pm    
This is so wrong in so many ways,...

Quote:
writes the hits to the textfile when the website is opened from the server's brower. if the website is opened on another computer, it does not write hits to the text file

That is because you are writing to
Quote:
"\\cci-opsweb01\TTHitCount\HitCounter.txt"
which exists on the server and not on the client's machine where the browser is opened and the code is executed. Remeber that the script is executed on the machine where the browser is opened with your URL.

If you want the hit counter to be updated on the server, you need to post the 'hit' to the server.

http://helpingdotnet.blogspot.com/2011/10/page-hit-counter-using-application-in.html[^]
http://magwebonline.blogspot.com/2013/01/create-page-hit-counter-in-aspnet.html[^]
http://www.codingasp.net/2011/09/unique-visiter-counter-in-aspnet.html[^]
http://highoncoding.com/Articles/78_Implementing_Hit_Counter_in_Asp_net.aspx[^]


Or rather use the free hit counters available on the internet . e.g www.statcounter.com
 
Share this answer
 
v2
If you want to find out the no of page hits, you can simply use log parser which can be downloaded free and then written to a csv file. Read the articles below:

http://www.sanjeevnandam.com/blog/extract-information-from-an-iis-log[^]

http://mlichtenberg.wordpress.com/2011/02/03/log-parser-rocks-more-than-50-examples/[^]

Thanks
Sameera
 
Share this answer
 
it is a html website. it works when the website is opened from the server's internet explorer
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900