Counters Code

  Home arrow Counters Code arrow Logs referer, IP/Hostname, time, and b...
COUNTERS CODE

Logs referer, IP/Hostname, time, and browser type
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-01-18

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    A modification to Simon Steed's mod of Tyler Longren's Logger. It will now only track _NEW_ visitors to your site not every hit on every page as it did befor. You can also use it as a hit counter by grabbing the number of rows from the DB.

    By : svonwolf

    <?
    // Hit and visitor counter
    $connection = mysql_connect($hostName, $userName, $password) or die ("Unable to connect to MySQL server.");
    $db = mysql_select_db($databaseName) or die ("Unable to select requested database");

    $browser = $HTTP_USER_AGENT;
    $date = date("F jS Y, h:iA");

    // Check if the referer is your site if not then add record
    if (preg_match ("/www.YOUR_DOMAIN.com/i", "$HTTP_REFERER")) {
    mysql_close($connection);
    } else {

    // If you cant resolve domain use IP address
    if ($REMOTE_HOST == "") {
    $host = $REMOTE_ADDR;
    } else {
    $host = $REMOTE_HOST;
    }

    if( empty( $HTTP_REFERER ) or '' == $HTTP_REFERER ) {
    $HTTP_REFERER = 'No Referer';
    }

    mysql_query ("INSERT INTO statinfo (browser, date, host, referer) VALUES ('$browser','$date','$host','$HTTP_REFERER' )");

    mysql_close($connection);
    }
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Counters Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    COUNTERS CODE ARTICLES

    - TG Who's Online
    - Text Based Counter that formats output
    - Counter & visitor statistics
    - Server Uptime Statistics
    - Chris Dingman's Hit Tracker Script
    - Graph Maker Function
    - Simple userOnline class
    - Adv. Log file generator
    - Logwriter
    - time_left()
    - Basic Statistics
    - Easy Counter
    - countCodeLines
    - MySQL Counter
    - bandwidthmeter


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap