Daily Hits ASP Script - ASP Web Pro
  Active Server Pages Programming by ASP Web Pro

ASP Scripts

DAILY HITS

Another popular web statistic to track is the number of daily hits your website receives. There are several ways to accomplish this using a global.asa file, text file, or a database. In this example, we are using an include file to record the data in an MS Access database.

The first thing you need to do is create a dailyhits.asp page with the code below:

<!--#INCLUDE VIRTUAL="/includes/connaction.asp" -->

<%
DIM mySQL, objRS
mySQL = "SELECT * FROM tblDailyHits WHERE DateVisited = #" & Date() & "#;"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText

DIM iRecordCount
iRecordCount = 0
IF objRS.EOF THEN
objRS.AddNew
ELSE
objRS.MoveFirst
iRecordCount = objRS("Hits")
END IF
objRS("Hits") = iRecordCount + 1
objRS.Update
%>

We have <% =objRS("Hits") %> hits today.

<%
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>

Next, we add our dailyhits.asp include file to every page in our website as seen below:

Note: If you are using an HTML Editor like FrontPage or Dreamweaver, you can save time by placing your include file in your shared border or template. Then, your dailyhits.asp file will autmatically be included in every page that uses that shared border or template.

<!-- #INCLUDE VIRTUAL="/YOUR FILE PATH HERE/dailyhits.asp" -->
<HTML><HEAD>
<TITLE>ASP Web Pro</TITLE>
</HEAD>

<BODY>

The rest of your page here.

</BODY>
</HTML>

Now, you have a count of how many Daily Hits you are receiving on your website.

< Back to ASP Scripts


 

 

Main Menu
Home
ASP Scripts
ASP Tutorials
JavaScripts
Awards
Contact Us

Email This Page

Other Resources
ASP Web Hosting
Search Engine Submission
Programming Help

 

 

 

Other ASP Web Sites

Site Map

 

Last Updated:
09 May 2008