Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $old_error_handler = set_error_handler("userErrorHandler");
- // we will do our own error handling
- error_reporting(0);
- // user defined error handling function
- function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
- {
- // timestamp for the error entry
- $dt = date("Y-m-d H:i:s (T)");
- // define an assoc array of error string
- // in reality the only entries we should
- // consider are E_WARNING, E_NOTICE, E_USER_ERROR,
- // E_USER_WARNING and E_USER_NOTICE
- $errortype = array (
- E_ERROR => 'Error',
- E_WARNING => 'Warning',
- E_PARSE => 'Parsing 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',
- E_STRICT => 'Runtime Notice',
- E_RECOVERABLE_ERROR => 'Catchable Fatal Error'
- );
- // set of errors for which a var trace will be saved
- $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
- $errtype = $errortype[$errno];
- $err = "<errorentry>\n";
- $err .= "\t<datetime>" . $dt . "</datetime>\n";
- $err .= "\t<errornum>" . $errno . "</errornum>\n";
- $err .= "\t<errortype>" . $errtype . "</errortype>\n";
- $err .= "\t<errormsg>" . $errmsg . "</errormsg>\n";
- $err .= "\t<scriptname>" . $filename . "</scriptname>\n";
- $err .= "\t<scriptlinenum>" . $linenum . "</scriptlinenum>\n";
- if (in_array($errno, $user_errors)) {
- $err .= "\t<vartrace>" . wddx_serialize_value($vars, "Variables") . "</vartrace>\n";
- }
- $err .= "</errorentry>\n\n";
- $file = $filename;
- $file = str_replace("H:\\xampp\\htdocs\\!webpaket","", $file);
- $err2 = "<b>".$errtype.":</b><br>".$errmsg."<br>in Zeile ".$linenum."<br>".$file."<br>";
- if(isLocal())
- {
- $t = file($filename);
- $von = $linenum-4;
- if($von<0) $von=0;
- $bis = $linenum+4;
- $err2.="<div class=error>";
- for($i = $von; $i <= $bis; $i++)
- {
- if($i==$linenum-1) $err2.="<span>";
- $zeile = $t[$i];
- $zeile = str_replace("\t"," ", $zeile);
- $err2.= $zeile;
- if($i==$linenum-1)
- {
- $err2.="</span>";
- }else{
- $err2.="<br>";
- }
- }
- $err2.="</div>";
- }
- $err2.="<br>";
- // for testing
- header("HTTP/1.1 500 Internal Server Error");
- //echo $err;
- echo $err2;
- // save to the error log, and e-mail me if there is a critical user error
- //error_log($err, 3, "/usr/local/php4/error.log");
- if ($errno == E_USER_ERROR) {
- //mail("phpdev@example.com", "Critical User Error", $err);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement