Creating an ASP WEB Page hit counter with Godaddy Windows Economy Hosting.

 
This page explains how to create a simple hit counter with Godaddy Windows Economy hosting. The hit counter consists of a Server Side Include using ASP which will update a text file stored on the Godaddy hosting site. The text file can then be read from an ASP script so you can quickly check the page hit count.

1.) Create a folder to store your text files:
Logon to Godaddy.com and select Hosting - Hosting Management from the menu.

Launch the Hosting Control Center for your hosting account.

From the Content menu
select FTP File Manager.

 
Select Create New Directory

.
Name the New Directory "count"

Set the permissions on the new directory to Read / Write.

Make sure the ASP Add-on language is enabled as well.

 

2.) Create the ASP script file to count page hits.
From your WEB editor create a new HTML document called "count_home.asp" and copy/paste the code below into that document.  There should be no other text in the "count_home.asp" WEB page.

<%

Call CountThisUser

Sub CountThisUser()

Dim objFSO ' FileSystemObject
Dim objTS ' TextStreamObject

Dim strFileName ' Counter text File Name
Dim intOldCount
Dim intNewCount

strFileName = Server.MapPath("count/Counter_home.txt")

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists(strFileName) Then
Set objTS = objFSO.OpenTextFile(strFileName, 1)
Else
Set objTS = objFSO.CreateTextFile(strFileName, True)
End If

If Not objTS.AtEndOfStream Then
intoldCount = objTS.ReadAll
Else
intoldCount = 0
End If

objTS.Close

intNewCount = intOldCount + 1

Session("TotalCount")= intNewCount

Set objTS = objFSO.CreateTextFile(strFileName, True)
objTS.Write intNewCount

objTS.Close

Set objFSO = Nothing
Set objTS = Nothing
End Sub

%>

Use your upload method (such as FTP) to upload "count_home.asp" to the root of your WEB site.

3.)  Place the Server Side Include in your Home Page.  It should go in the Head section of your WEB page.  The include code is:
<!--#Include File="Count_home.asp"-->

4.) Name your Home Page "default.asp".  Default.asp has higher priority than most other home page names at Godaddy.  If your home page is currently named "index.htm" then default.asp will load before index.htm.  The page must have the .asp extension in order for the Server Side Include to work.  The first time you load default.asp by accessing your WEB site the file "Counter_home.txt" will be created in the "/count" directory on your hosting site with the number 1 in it.
Note: it may error on the first open but refreshing will clear that and from then on it will update the .txt file with each subsequent open.

 4.) Viewing your page hits:
To view the .txt file you need to create another ASP Page called "count_disp.asp".  Copy/Paste the following code into this page.

<html>
<body>
<p>Home page hits:</p>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")

Set f=fs.OpenTextFile(Server.MapPath("counter_home.txt"), 1)
Response.Write(f.ReadAll)
f.Close

Set f=Nothing
Set fs=Nothing
%>

Use your upload method (such as FTP) to upload "count_disp.asp" to the /count directory of your WEB site.  You can then create a link from your home page to "count_disp.asp".   When the link is opened you will get a result like this:

Each time someone visits your WEB page the count number will increase by one.  You can use the same method to create a hit counter for other pages on your WEB site.  Do this by modifying the code of the "count_home.asp" above to change the map path to a different text file such as "gallery".  And save the count_home.asp as count_gallery.asp. 

strFileName = Server.MapPath("count/Counter_gallery.txt")

Then on your gallery WEB page add the server side include for count_gallery.asp:

<!--#Include File="Count_gallery.asp"-->

Finally just duplicate the code in "count_disp.asp" with the map path modified to read and display both the "counter_home.txt" and "counter_gallery.txt" files.
 

<html>
<body>
<p>Home page hits:</p>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")

Set f=fs.OpenTextFile(Server.MapPath("counter_home.txt"), 1)
Response.Write(f.ReadAll)
f.Close

Set f=Nothing
Set fs=Nothing
%>

<p>Gallery page hits:</p>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")

Set f=fs.OpenTextFile(Server.MapPath("counter_gallery.txt"), 1)
Response.Write(f.ReadAll)
f.Close

Set f=Nothing
Set fs=Nothing
%>

Use this method to create a simple page hit counter for each of the pages in your WEB Site.


Questions or feedback ?



Close this window