Save your 404-not found referrers in a text file

Views: 1690 Last modified: September 17th, 2011 Comments: 0

This class will save some basic visitor information in a defined text file so you have a little opportunity to track your 404-not found situations.

<?php

class NotFound_404 {
    # Path to file
    const ErrorFile = 'path/to/file.txt';

    # Vistor 404 time
    public $visitor_time = '';

    # Visitor full request uri
    public $visitor_full_uri = '';

    # Visitor request uri
    public $visitor_request_uri = '';

    # Visitor Refferer
    public $visitor_referer = '';

    # Construct
    function __construct()
    {
        $this->visitor_time = date('Y F-d H:i:s', strtotime('now', time()));
        $this->visitor_request_uri = $_SERVER['REQUEST_URI'];
        $this->visitor_full_uri = ($_SERVER['HTTPS'] == 'on') ? 'https://'.$_SERVER['HTTP_HOST'].$this->visitor_request_uri : 'http://'.$_SERVER['HTTP_HOST'].$this->visitor_request_uri;
        $this->visitor_referer = $_SERVER['HTTP_REFERER'];
    }

    # Log the error
    public function Log404Error()
    {
        $Notice_404 = "\r\n Visitor Time: ". $this->visitor_time ."\r\n Visitor request URI: ". $this->visitor_request_uri ."\r\n Visitor Full URI: ". $this->visitor_full_uri .
                        "\r\n Visitor Referer: ". $this->visitor_referer ."\n\r\n----------------------------------------\r\n";
        error_log($Notice_404, 3, self::ErrorFile);
        return;
    }

    function __destruct()
    {
        unset($this->visitor_time, $this->visitor_full_uri, $this->visitor_request_uri, $this->visitor_referer);
    }
}

?>
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)
    Bluehost

    Mail this!

    To: From:Sum {5+8} =  
    Anything to add ?

        You must be logged in to post a comment.