ASP
  Home arrow ASP arrow Page 2 - A Simple Way To Tally Your Visitors
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

A Simple Way To Tally Your Visitors
By: Burag Cetinkaya
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 8
    2002-01-20

    Table of Contents:
  • A Simple Way To Tally Your Visitors
  • Creating our hit counter
  • Displaying the hit counter
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    A Simple Way To Tally Your Visitors - Creating our hit counter


    (Page 2 of 4 )

    Let's start by opening Microsoft Access 2000. Create a new access database with the file name hit_counter.mdb and save it in the your web browsers root directory. Create the following table named "Hits" as part of that database:

    The design of our hits table

    Our hits table will be used to store the details of each individual visit to our site from one user on any particular day. In our case, a "user" is a unique I.P. address. The hits table contains four fields:
    1. ID: An auto number that is automatically assigned to each new row added to the table.
    2. Hit_Date: Will store the date that the "hit" was recorded
    3. Hit_Time: Will store the time that the "hit" was recorded
    4. Hit_IP: Will store the I.P. address of the user for which the "hit" was recorded.
    The code to both record and tally hits on any unique day will be stored in one single file named hit_counter.asp. Every time a new, unique visitor (differentiated by their I.P. address) comes to our site on any particular day, a new record is added to the hits table to record the date, time and their I.P. address. The code to do this should be placed in hit_counter.asp and looks like this:

    <%

    Dim Conn

    Dim RS

    Dim TotalVisited

    Dim ImgSequence

    Dim CharToReplace

    Dim Query

    Set Conn = Server.CreateObject("ADODB.Connection")

    Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("hit_counter.mdb")

    Set RS = Server.CreateObject("ADODB.Recordset")

    Query = "SELECT * FROM Hits WHERE Hit_IP='" & Request.ServerVariables("REMOTE_ADDR") & "' AND Hit_Date=#" & DATE() & "#"

    RS.Open Query, Conn, 3, 3

    'If this is the first visit from this IP

    IF RS.EOF AND RS.BOF THEN

    RS.AddNew

    RS("Hit_Date") = Date()

    RS("Hit_Time") = Time()

    RS("Hit_IP") = Request.ServerVariables("Remote_Addr")

    RS.Update

    END IF

    RS.Close

    %>


    We're using an ADO connection object to connect to our Microsoft Access database using a query string, which specifies the driver type and physical location of our database file. We build a query that will retrieve any rows in our hits table where the Hit_Date field matches today's date, and where the visitors I.P. address matches the Hit_IP field in the hits table. The value of the REMOTE_ADDR variable in the Request.ServerVariables collection holds the I.P. address of the visitor. We assign our query to a variable named query. The query looked like this when I accessed the hit_counter.asp file from my local machine on the 20th January 2002:

    SELECT * FROM Hits WHERE Hit_IP='127.0.0.1' AND Hit_Date=#20-Jan-02#

    This is only one part of our counter script, however, we can still run it through our web browser to see some results. The first time you run it, a new record will be inserted into the hits table of our hit_counter.mdb database. If, however, you hit refresh in your browser, then you’ll notice that a second record has not been added. As described earlier, only one record per unique I.P. address per day is added to the hits table. This allows us to accurately track how many unique visitors our site has received.

    More ASP Articles
    More By Burag Cetinkaya


     

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT