- ASP - Read/Write
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·What's New?
Mail List


Hit Counter (With A DB)
There are many ways to track the usage of a website. The simplest way is with a hit counter. The following example will accumulate hit statistics and store them in an Access db and display the current hit count on the current page.  Prior to insertion into the db the full url is constructed including any value(s) passed to the .asp in the address bar (a feature you may or may not want on your site). While Access is perfectly fine for this demonstration or a site that does not get that much simultaneous traffic Access is not the recommended database management solution (DBMS) for larger site statistics.
View the Output
Text View
Print View
Mail this Link
Download the Code
View the Data

<a href=hitcounterdb.asp>hitcounterdb.asp</a><br>
<a href=hitcounterdb.asp?anyvariable=any_value>hitcounterdb.asp?anyvariable=any_value</a><br>

' Builds a variable page with the absolute location of the page
' Create the http://anydomain.ext/
page= "http://" & request.servervariables("SERVER_NAME") 

' Add the page on the server being counted to the page variable
page= page & request.servervariables("script_name")

' Check for any text after the filename to the page variable
' If you're not interested in querystring in you data remove
' from here to the end if
qstring= request.servervariables("query_string")
if trim(qstring) <> "" then
' Add any text after the filename to the page variable
page= page & "?" & qstring
end if ' end querystring routine

' Open a connection to the hitcounterdb
cn="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn & "DBQ=" & server.mappath(accessdb)
Set rs = Server.CreateObject("ADODB.Recordset")

' Insert the url for the page and the number one for the number of hits
' The Accessdb is set up to also post the date and time into the db 
sql = "insert into hitcounter (page,hit)"
sql = sql & " values( '" & page & "',1 )" 
rs.Open sql, cn

'This area displays the current hit count from the db
' Select statement to count the number of hits for the current page
sql= "SELECT Sum([hit]) AS hits FROM hitcounter where page='"& page &"'"
rs.Open sql, cn

' Write out the current hit count to the browser
<%= page %> <br>
has been visited <%= rs("hits") %> times




ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
  • 2014 michael kors
  • air max women 2013
  • 2014 michael kors
  • air max 2014
  • oakley glasses
  • oakley glasses

  • Maps: Map Script Writers | Bing Maps | Google Maps
  • bottes fr
  • ugg boot
  • Privacy Statement is hosted by
    Donate Food Online with a Mouse Click at
    Donate Land Online with a Mouse Click at
    © 1999 - 2018
    All Rights Reserved

  • Kids jordan 6 rings
  • Jordan retro 10
  • Jordan retro 3