Total Hits with Database

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

To do this, create a /TotalHits.asp page in your /includes/ directory with the code below:

<!--#include virtual="/includes/connection.asp" -->

DIM mySQL, objRS
mySQL = "SELECT * FROM tblTotalHits"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText

DIM iRecordCount
iRecordCount = objRS("Hits")
objRS("Hits") = iRecordCount + 1

<p>Our website has received <% =objRS("Hits") %> Total Hits.</p>

Set objRS = Nothing
Set objConn = Nothing


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

<!-- #include virtual="/includes/totalhits.asp" -->

<p>The rest of your page here.</p>

Now, you have a count of how many Total Hits your website has received.

< Back to ASP Scripts