Forums

This topic is locked

Hit Counter

Posted 29 Mar 2004 18:20:32
1
has voted
29 Mar 2004 18:20:32 Brian Welch posted:
Hello All,

I'm brand new to DMX but have managed to post a basic HTML site. As my next learningstep, I'd like to have a hit counter on the site.

I'd rather have my own than a comercial one. I managed to find the .ASP code below (if this helps) but just don't know how to make this work.

Where does this fit into DMX, is there a better way to do this ?

If someone can point me in the right direction please, from start to finish I'd appreciate it.

Thanks very much -- Brian





<%
' Declare our vaiables
Dim objFSO, objCountFile ' object vars for FSO and File
Dim strCountFileName ' filename of count text file
Dim iCount ' count variable
Dim bUseImages ' boolean whether or not to use images
Dim I ' standard looping var

' Determine whether we use images or plain text
' You could just set this to True or False instead
bUseImages = CBool(Request.QueryString("images")

' Compute our count file's filename
' This is based on the file from which you call count.asp
' It basically takes that name and appends a .cnt so I don't
' accidently overwrite any files. If for some reason you have
' a file named script_name.asp.cnt then change this or watch out!
strCountFileName = Server.MapPath(Request.ServerVariables("SCRIPT_NAME" & ".cnt"

' Create FileSystemObject to deal with file access
Set objFSO = Server.CreateObject("Scripting.FileSystemObject"

' Open the file as a text stream (1 = ForReading, True = Create)
Set objCountFile = objFSO.OpenTextFile(strCountFileName, 1, True)

' Read the current count from the file
If Not objCountFile.AtEndOfStream Then
' Set value to contents of the file
iCount = CLng(objCountFile.ReadAll)
Else
' If no file exists or it's empty start at 0
iCount = 0
End If

' Close the file and destroy the object
objCountFile.Close
Set objCountFile = Nothing

' Increment the count
iCount = iCount + 1

' Overwrite existing file and get a text stream to new one
Set objCountFile = objFSO.CreateTextFile(strCountFileName, True)

' Write updated count
objCountFile.Write iCount

' Close the file and destroy the object
objCountFile.Close
Set objCountFile = Nothing

' Destroy the FSO object
Set objFSO = Nothing

' We're all done with the hard part
' All that's left is to display the results
If bUseImages Then
' Loop through the count integer showing each digit
For I = 1 to Len(iCount)
' Output the IMG tag using the right digit
Response.Write "<img src=""/images/digit_"
Response.Write Mid(iCount, I, 1)
Response.Write ".gif"" alt="""
Response.Write Mid(iCount, I, 1)
Response.Write """ width=""20"" height=""26"" />"
Next 'I
Else
' No image wanted just show the variable
Response.Write iCount
End If
%>

Replies

Replied 29 Mar 2004 18:25:07
29 Mar 2004 18:25:07   replied:
You would have to make the page an .asp page.
Hit counters are not a true count of visitors to your site. I can go to your site and repeatedly click back and for on my browser and rack up your hit counter. Check your host to see if they can email you weekly stats of your site. It will tell you unique vistors rather than hits.
Replied 30 Mar 2004 01:35:07
30 Mar 2004 01:35:07 Phil Shevlin replied:
Are you wanting to code it yourself -- or get a working hit counter script?
Replied 30 Mar 2004 09:35:33
30 Mar 2004 09:35:33 Brian Welch replied:
Thanks for the responses. I know a counter isn't a true reflection on visitors but I'd still like to add one and to try and learn a little more.

Yes I'd like to code it but am willing to look at adding a counter but I didn't really want one that reference another site etc.... I'd rather have my own (if you see what I mean).....

Agaim, your help/time is greatly appreciated..............
Replied 30 Mar 2004 13:43:15
30 Mar 2004 13:43:15 Phil Shevlin replied:
The one you have looks like it would work. Just place that code where you want the counter to appear. Optionally you can make it an include and place the include line where ever you want the counter
Replied 30 Mar 2004 14:51:23
30 Mar 2004 14:51:23 Brian Welch replied:
Hi wdglide,

Thanks, I've got the code in a brand new DMX file and this 'runs' and the page displayed is totally blank. This is the bit I think I'm missing and need some 'step pointers on. For example,

1) Paste the code into a project
2) ....
3) ....
4) ....

etc....

I'm not too sure how to call this code or to use include files ---> I know I should look at all the help files etc.. but i'm getting stuck so have turned to the people answers...

Thanks
Replied 31 Mar 2004 02:26:59
31 Mar 2004 02:26:59 Phil Shevlin replied:
All you need to do with that code is paste it - period.

If its not working, I guess its possible that the directory is write-protected. But that should throw some errors. The code worked fine for me.
Replied 31 Mar 2004 11:00:35
31 Mar 2004 11:00:35 Brian Welch replied:
Sorry still no joy........... I've pasted the code and run locally (using F12) and all I get is a blank bowser page, with nothing displayed. No counter and no errors either.

Looks like I'm really missing something here !!!! I do appreciate hour help with this
Replied 31 Mar 2004 13:38:26
31 Mar 2004 13:38:26 Phil Shevlin replied:
.asp can only run on a web server. It wont work locally. Thats your problem
Replied 31 Mar 2004 17:15:47
31 Mar 2004 17:15:47 Brian Welch replied:
ok, I;ve included the code within a site I have running and have just copied and pasted the .ASP code into the header of the Index.htm page.

I re. uploaded this and ensured all of the image files are uploaded too in the sub directory of /images but still no joy......

you help's been great but it's not doing it for me........ should I just give up and be frustrated or can someone help me more.....

Replied 01 Apr 2004 00:43:59
01 Apr 2004 00:43:59   replied:
Your trouble lies with the fact that your using an .htm page to display and asp code. Change it to a asp page and also check your host to see if you can run asp and if index.asp is set up as the default page.
Replied 30 Apr 2004 22:24:57
30 Apr 2004 22:24:57 v mr. replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
i also got this working...the only thing i can't figure out is how to get the images showing...i created an image and it won't display...the text keeps displaying...any reason why?<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 01 May 2004 00:52:25
01 May 2004 00:52:25 Phil Shevlin replied:
How are you using it? As an include? Do you pass the querystring...

?bUseImages=1

... with the include?
Replied 03 May 2004 17:50:27
03 May 2004 17:50:27 v mr. replied:

i am new at .asp...i basically pasted the code on a blank page and it displayed out the number of times the page was viewed in text format...just wondering how could i have it show an image of numbers instead of text format...also, are there any good wesites to learn asp...
thanks...
Replied 04 May 2004 00:53:32
04 May 2004 00:53:32 Phil Shevlin replied:
change the line that says...

bUseImages = CBool(Request.QueryString("images")

to..

bUseImages = true
Replied 06 May 2004 17:33:07
06 May 2004 17:33:07 v mr. replied:
that worked, but i get a broken picture...i tried creating an image called digit1.gif, for the number one, and it didn't work...the code has it as: img src""/digit_"?
-thanks again for your help-
Replied 08 May 2004 04:10:59
08 May 2004 04:10:59 Phil Shevlin replied:
2 things.

The images must be named digit_1.gif, digit_2.gif, etc

Paste the source of the resulting page here so I can see the results.
Replied 10 May 2004 18:48:24
10 May 2004 18:48:24 v mr. replied:
i actually went with some different code...my only concern now is when they refresh a page it keeps counting...probably not good...but its simple...i appriciate all of your help...i checked out your site...excellent...very sharp!...
thanks again...

Reply to this topic