PDA

View Full Version : ASP Counter


poky
11-10-2002, 04:15 PM
hEllO all, I can not creat my counter page. I have 3 files on File Manager to creat a ASP counter file, but it doesn't work.

First , is the file counter.asp with its content :
<%
%>
<html>
<head>
<title>Hit Counter</title>
</head>
<body>
<%
Dim fsoObject 'File System Object
Dim tsObject 'Text Stream Object
Dim filObject 'File Object
Dim lngVisitorNumber 'Holds the visitor number
Dim intWriteDigitLoopCount 'Loop counter to display the graphical hit count
Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")
Set filObject = fsoObject.GetFile(Server.MapPath("hit_count.txt"))
Set tsObject = filObject.OpenAsTextStream
lngVisitorNumber = CLng(tsObject.ReadAll)
lngVisitorNumber = lngVisitorNumber + 1
Set tsObject = fsoObject.CreateTextFile(Server.MapPath("hit_count.txt"))
tsObject.Write CStr(lngVisitorNumber)
Set fsoObject = Nothing
Set tsObject = Nothing
Set filObject = Nothing
Response.Write(lngVisitorNumber)
%>
</body>
</html>

Second , is hit_counter.txt with this content
1

Third, is my index.htm with this content
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>Fantastic website </title>
</head>

<body>
<body bgcolor="#FFFFFF">

<p align="center"><img src="leftheart.gif" width="56" height="54"><font
color="#8000FF" size="5" face="Verdana"><marquee width="75%">Fantastic web - Designed and created by Han Nhi</marquee></font><img
src="rightheart.gif" width="58" height="54"></p>

<p align="center">&nbsp;</p>

<table border="0">
<tr>
<td colspan="40"

<p><a href="http://hannhi.topcities.com/guestbook.html"><img
src="heart.gif" alt="Loving Box" border="0" width="17"
height="16"></a><font face="Verdana"> </font><a
href="http://hannhi.topcities.com/guestbook.html"><font
face="Verdana">Loving Box</font></a><font face="Verdana">
</font></p>

<p><font color="#FF0000"><strong>»»»» </strong></font></p>


<p><font color="#804040" face="Verdana"><strong>Pls show
me ur idea by signin' in this part :) Thanks</strong></font></p>
</tr>
</table>

<p align="center"><font face="Tahoma">Contact me : </font><a
href="mailto:hannhi@mail2honey.com"><font color="#0000FF"
face="Tahoma"><u>hannhi@mail2honey.com</u></font></a></p>

<p align="center"><font color="#0000FF" face="Tahoma">There are <!--#INCLUDE FILE="counter.asp" --> visiters</font></p>
</body>
</body>
</html>


That's all. But My counter visiters doesn't work, anyone tell me why ??

whammy
11-10-2002, 05:33 PM
Hmm, not exactly sure - but one thing I noticed right away is you appear to have named the text file "hit_counter.txt" and the script is looking for "hit_count.txt".

Also, you are attempting to include a file into an HTML page with .asp, and you can't do that. If you are going to include a file you have to use the .asp extension (unless you have specified otherwise in IIS).

Perhaps this one will be simpler to use:

http://www.solidscripts.com/displayscript.asp?sid=4

:)

glenngv
11-12-2002, 07:14 AM
yeah that's simple but it did not mention where to put that hit counter code.

in my intranet site here in our office, i have a hit counter and the code is in Session_OnStart in global.asa. I put the current count in a session variable so that i can display it in the home page.
When the code is in Session_OnStart, you can be sure that a hit is counted once any page other than the homepage is accessed first by the user. But through experience, ONLY asp files accessed triggers that event. If the user runs an .htm file first, Session_OnStart is NOT triggered.

The workaround is to insert these js codes in every htm page.

//this is called when any html file is directly access from the server without going to the home page or any asp page
if (document.referrer==""){
loghits = new Image();
loghits.src="/dummy.asp"; //call a dummy asp file to trigger global.asa to be executed
//NOTE:you may want to check if document.referrer comes from your domain
}

the dummy.asp file is actually an empty asp file.
i saved the above code in an external js and inserted it in every .htm page.
that will be too messy if you have many .htm files in your site. but that's the only way i could think of to accurately count the number of visits in your site.
hope this helps! :)

poky
11-12-2002, 07:51 AM
Thank you so much, but I have another question : Doesn't the brinkster.com support asp counter ??

glenngv
11-12-2002, 08:00 AM
brinkster supports write permissions to db directory where you can save your Access db and write files thru FileSystemObject

poky
11-12-2002, 08:54 AM
exactly, what is db ??

BigDaddy
11-12-2002, 02:35 PM
db = database. Brinkster gives you a folder for your databases to reside in.

whammy
11-12-2002, 04:15 PM
That counter script I showed you is ready to use on brinskter. :) It already has the path to your database folder mapped.