\n";
$r .= "
\n";
$r .= "
PHP ".$errorType." #".$errno."
\n";
$r .= "
".nl2br($errstr)."
\n";
$r .= "
$errfile on line $errline
\n";
$r .= "
";
$r .= "
\n";
if (count($trace)) {
//backtrace
$r .= "
\n";
$r .= "
Backtrace
\n";
$r .= "
\n";
foreach ($trace as $step) {
$r .= $step['file']."(".$step['line']."): ".$step['function']."\n";
$files[] = array('file' => $step['file'], 'line' => $step['line']);
}
$r .= "
\n";
$r .= "
\n";
$r .= "
\n";
}
//print all files from the backtrace
foreach ($files as $file) {
$r .= printErrFile($file['file'], $file['line']);
}
$r .= "
\n"; //Surrounding white background div
if (defined('ERROR_STD')) {
echo $r;
}
if (defined('ERROR_EMAIL')) {
$boundary = strtoupper(md5(uniqid(time())));
$header = "From: noreply@nambu.ch (PHP Errorhandler)";
$header .= "\nX-Mailer: PHP ". phpversion();
$header .= "\nMIME-Version: 1.0";
$header .= "\nContent-Type: multipart/mixed; boundary=$boundary";
$header1 = "\n\nThis is a multi-part message in MIME format -- Dies ist eine mehrteilige Nachricht im MIME-Format";
$header1 .= "\n--$boundary";
$header1 .= "\nContent-Type: text/html";
$header1 .= "\nContent-Transfer-Encoding: 8bit";
$header1 .= "\n\n$r";
/* Hier faengt der Datei-Anhang an */
$header1 .= "\n--$boundary";
$header1 .= "\nContent-Type: application/octetstream; name=\"session.txt\"";
$header1 .= "\nContent-Transfer-Encoding: base64";
$header1 .= "\nContent-Disposition: attachment; filename=\"session.txt\"";
$header1 .= "\n\n";
$header1 .= chunk_split(base64_encode("\$_SESSION: ".print_r($_SESSION, true)));
/* Gibt das Ende der eMail aus */
$mail_header .= "\n--$boundary--";
mail(ERROR_EMAIL, "Catched PHP Error", $header1, $header);
include "errorpage.html";
}
//error happened. stop execution!
if ($errno != 2) {
exit(1);
}
}
/**
* @param string $errfile
* @param string $errline
* @return string
*/
function printErrFile($errfile, $errline) {
$lines_prev = 10;
$lines_next = 5;
$lines = file($errfile);
$lines_start = ($errline - $lines_prev <= 0) ? 0 : $errline - $lines_prev;
$lines_end = (count($lines) < $errline + $lines_next) ? count($lines) : $errline + $lines_next;
//$variables = array();
$r = "\n";
$r .= "
Source-Code: ".$errfile." (".$errline.")
\n";
$r .= "
\n";
for ($i = $lines_start; $i < $lines_end; $i++) {
$divattr = "";
$line = $i + 1;
if ($line == $errline) $divattr .= " style='background-color: #FFFFFF; width: 100%'";
$r .= "".sprintf("%02d", $line)." ".htmlentities($lines[$i])."";
}
$r .= "
\n";
$r .= "
\n";
$r .= "