404 Logging

Published On: 2012-01-02

Category: News

<?php
$logFile = $_SERVER['DOCUMENT_ROOT'].'/404.log';   // full path to your log file
date_default_timezone_set('TZ=CST6CDT');  // set to your time zone

if (isset($logFile)) {
 $logData = '404|'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'|'.$_SERVER['REMOTE_ADDR'].'|'.$_SERVER['HTTP_USER_AGENT'].'|'.$_SERVER['HTTP_REFERER'].'|'.date('Y-m-d
H:i:s')."\r\n";
 if (
      !strstr($_SERVER['REQUEST_URI'],'_vti_bin') &&      //MS Office Toolbar
      !strstr($_SERVER['REQUEST_URI'],'MSOffice') &&
      !strstr($_SERVER['REQUEST_URI'],'/_vti_inf') &&
      !strstr($_SERVER['REQUEST_URI'],'javascript:false')  //Hack to
allow ie6 to work right
      //!strstr($_SERVER['HTTP_USER_AGENT'],'Googlebot-Image/1.0') &&
//Googlebot still links to tons of old images
    ) file_put_contents($logFile,$logData,FILE_APPEND|LOCK_EX);
}
?>