<?php 

$_ERROR_REPORTING_LEVEL = E_ALL;   // what errors to look out for. See www.php.net/error_reporting for more info 
$_EXIT_ON_ALL_ERRORS = true; 
$_ERROR_FILE = "";      // write the error message at the end of this file 
$_ERROR_MAILTO = "";   // email the error message to this email address 
$_ERROR_DISPLAY = false;   // display the error message in the script output 
$_ERROR_LOG_MESSAGE = "%date: The following %error occurred at line %line in file %file:\n";   // logged error message 
$_ERROR_LOG_MESSAGE .= "%msg\nThe IP address where this request came from was %ip\n"; 
$_ERROR_LOG_MESSAGE .= "The request method used was %method.\nThe querystring was %query.\n"; 
$_ERROR_EXIT_MESSAGE = "Sorry, an error occurred whilst processing you request.<br><br>";   // message to display to browser 
$_ERROR_EXIT_MESSAGE .= "The webmaster has been notified.<br><br>Please try again later.";   // when fatal error occurs 
$_ERROR_WARNING_MESSAGE = $_ERROR_EXIT_MESSAGE;      // message to display to browser when non-fatal error occurs 

function errorhandler ($errno, $errstr, $errfile, $errline) { 

   global $_ERROR_FILE, $_ERROR_MAILTO, $_ERROR_DISPLAY, $_ERROR_LOG_MESSAGE, $_EXIT_ON_ALL_ERRORS; 
   global $HTTP_SERVER_VARS, $_ERROR_EXIT_MESSAGE, $_ERROR_WARNING_MESSAGE; 

   $errs = array( E_ERROR => "Error", E_WARNING=>"Warning", E_PARSE => "Parse Error", E_NOTICE=>"Notice", 
               E_CORE_ERROR=>"Core Error", E_CORE_WARNING => "Core Warning", E_COMPILE_ERROR => "Compile Error", 
               E_COMPILE_WARNING => "Compile Warning",E_USER_ERROR=>"User Error",E_USER_WARNING=>"User Warning" 
               ,E_USER_NOTICE=>"User Notice"); 

   $search = array("%date", "%error", "%line", "%file", "%msg", "%ip", "%method", "%query"); 
   $replace = array(date("Y-m-d H:i:s"), $errs[$errno], $errline, $errfile, $errstr, $HTTP_SERVER_VARS["REMOTE_ADDR"], 
                     $HTTP_SERVER_VARS["REQUEST_METHOD"], 
                     (isset($HTTP_SERVER_VARS["QUERY_STRING"]) ? $HTTP_SERVER_VARS["QUERY_STRING"]: "empty")); 

   $errmsg = str_replace($search, $replace, $_ERROR_LOG_MESSAGE); 

   if( $_ERROR_FILE != "" ){   // log it to error file 
      error_log($errmsg, 3, $_ERROR_FILE); 
   } 

   if( $_ERROR_MAILTO != "" ){   // send an email with error message 
      error_log ($errmsg, 1, $_ERROR_MAILTO); 
   } 

   if( $_ERROR_DISPLAY == true ){   // display the error message 
      echo $errmsg; 
   } 

   if(  in_array($errno,array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR))){ 
      exit( $_ERROR_EXIT_MESSAGE); 
   }else{ 
      echo $_ERROR_WARNING_MESSAGE; 
   } 

   if(  $_EXIT_ON_ALL_ERRORS == true ) exit(); 

} 

error_reporting($_ERROR_REPORTING_LEVEL); 
set_error_handler("errorhandler"); 

?>