Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How can I count the number of hits on a link?

    I have a question :
    How can I count the number of hits on a link?
    thanks and goodbye

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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
    Code:
    <%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.AddNew
       objRs("requestedPage") = requestedPage
    End If
    objRs("hitCount") = (objRs("hitCount") + 1)
    objRs.Update
    objRs.close
    Set objRs = Nothing
    objConn.close
    Set objConn = Nothing
    Response.Redirect requestedPage
    3 Change the link in the original page
    Code:
    <a href="count-hits.asp?requestedPage=http://www.codingforums.com">
    There you go

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Check out the Forum Search. It's the short path to getting great results from this forum.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •