Tuesday, 29 November 2011

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, 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 totalhits.asp page with the code below:



<% DIM mySQL, objRS mySQL = "SELECT * FROM tblTotalHits" Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText DIM iRecordCount objRS.MoveFirst iRecordCount = objRS("Hits") objRS("Hits") = iRecordCount + 1 objRS.Update %>

Our website has received <% =objRS("Hits") %> total hits.

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

Next, we add our totalhits.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.



ASP Web Pro




The rest of your page here.




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

http://www.aspwebpro.com/aspscripts/statistics/totalhitsdb.asp

No comments:

Post a Comment