Counters Code

  Home arrow Counters Code arrow Adv. Log file generator
COUNTERS CODE

Adv. Log file generator
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2003-04-14

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    Set as your index.php and then change the $goto variable to your main entrance page. You can view the log either by downloading the Comma Seperated File it creates or you can type index?view and it will show you a nice little table generated from the Comma Seperated File.

    By : Rock

    <?php
    /*/-----------------------------------------\
    |Original Name : reflog.php |
    | Author : Neil |
    | Function : Generate a log of IP No.s |
    | and Exact Referring pages and the user |
    | agent after checking the HTTP_REFERER |
    | for a small expresstion. (Useful for |
    | checking the for a domain name in the |
    | HTTP_REFERER and then geting the entire|
    | path) |
    | You could run case or elseif's to run |
    | the check from multiple domains or |
    | expressions. You could get an exact |
    | log of refering pages if you were |
    | advertising, like in the original |
    | script, at Yell.co.uk. |
    \-----------------------------------------/

    Definition of variables
    Logstring is the string to insert in to the
    logfile
    The log file name is specified by filename
    regexp is the expression to search for in the
    URL
    */
    $date = gmdate("d/m/Y - H:i:s T"); //change to preffered format.
    $logstring = $date.",".$HTTP_SERVER_VARS['REMOTE_ADDR'].",".$HTTP_SERVER_VARS['HTTP_REFERER'].",".$HTTP_SERVER_VARS['HTTP_USER_AGENT']."\r";
    $regexp = strtoupper("yell.co.uk"); //String to filter for.
    $filename = "./reflog.csv";

    /*
    No cache!!
    */
    $goto = "http://www.yoursite.com/main.html";
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    // always modified
    header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache"); // HTTP/1.0
    /*
    End of No cache
    */


    function viewlog($filename) {
    $fp = fopen($filename,"r");
    $file = fread($fp,65535);
    $replaced = eregi_replace(",", "<td>", $file);
    $replaced2 = eregi_replace("\n", "<tr><td>", $replaced);
    $replaced3 = eregi_replace("\r", "<tr><td>", $replaced2);
    fclose($fp);

    return $replaced3;
    }
    if(isset($view)) {
    echo "<html><head><base href=\"./\"><title>Referer Log</title></head><body bgcolor=silver>";
    echo "<table border=0 bordercolor=black cellspacing=0 cellpadding=5 width=100% style='font-size:10pt'><tr><td><b>Date & Time</b><td><b>IP No.</b><td><b>Referring page</b><td><b>user agent</b><tr><td>";
    echo viewlog($filename);
    echo "</table></body></html>";
    exit;
    }
    else if (ereg($regexp, strtoupper($HTTP_SERVER_VARS['HTTP_REFERER']))) {
    $fp=fopen($filename, "a");
    if(!$fp) die ("Error opening file");

    fwrite($fp, $logstring);
    fclose($fp);
    }

    header("Location: $goto");
    ?>
    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 10 - Follow our Sitemap