View Full Version : How can I count the number of hits on a link?

09-04-2004, 07:58 PM
I have a question :
How can I count the number of hits on a link?
thanks and goodbye

09-04-2004, 08:38 PM
take a link listed like this <a href="http://www.codingforums.com">
to count the number of hits to that link from your page you could do this

1. create a table named pagehits in the database for hits. this will have 2 columns
hitCount 'an integar filed
requestedPage ' a text field

2 create a page which will count the hits in this example it is called count-hits.asp

<%Option Explicit
dim objConn, objRs, SQL, strRequested, connString
strRequested = Request.QueryString("requestedPage")
connString = "D:\WWWRoot\Database\myAccessDatabase.mdb;"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & connString)
SQL = "SELECT hitCount from pagehits WHERE requestedPage = '" & strRequested & "'"
Set objRs = Server.CreateObject("ADODB.Recordset")
objRs.open SQL, objConn, 1, 2
If objRs.EOF Then
objRs("requestedPage") = requestedPage
End If
objRs("hitCount") = (objRs("hitCount") + 1)
Set objRs = Nothing
Set objConn = Nothing
Response.Redirect requestedPage

3 Change the link in the original page

<a href="count-hits.asp?requestedPage=http://www.codingforums.com">

There you go

Roy Sinclair
09-07-2004, 07:35 PM
Check with your webhost to see if they've got web logging on/available. All the modern web server provide web logs detailing information about all the hits and how the server responded. If you can get that log you'll be able to count the hits for a specific page very precisely.