1){//prevents the error handler from being re-called when we're already within a call of it.
if ($errno & (E_USER_WARNING | E_WARNING)){
echo "PHP Warning: \"$errstr\"
in $errfile at $errline. Additionally this occurred while within logd_error_handler().
";
}elseif ($errno & (E_USER_ERROR | E_ERROR)){
echo "PHP ERROR: \"$errstr\"
in $errfile at $errline. Additionally this occurred while within logd_error_handler().
";
}
$in_error_handler--;
return;
}
switch($errno){
case E_NOTICE:
case E_USER_NOTICE:
if (getsetting('show_notices', 0) &&
$session['user']['superuser'] & SU_SHOW_PHPNOTICE) {
debug("PHP Notice: \"$errstr\"
in $errfile at $errline.");
}
break;
case E_WARNING:
case E_USER_WARNING:
require_once("lib/show_backtrace.php");
tlschema("errorhandler");
output("PHP Warning: \"%s\"`nin `b%s`b at `b%s`b.`n",$errstr,$errfile,$errline,true);
tlschema();
$backtrace = show_backtrace();
rawoutput($backtrace);
if (getsetting("notify_on_warn",0) > ""){
//$args = func_get_args();
//call_user_func_array("logd_error_notify",$args);
logd_error_notify($errno, $errstr, $errfile, $errline, $backtrace);
}
break;
case E_ERROR:
case E_USER_ERROR:
require_once("lib/show_backtrace.php");
echo sprintf("PHP ERROR: \"%s\"
in %s at %s.
",$errstr,$errfile,$errline);
$backtrace = show_backtrace();
echo $backtrace;
if (getsetting("notify_on_error",0) > ""){
//$args = func_get_args();
//call_user_func_array("logd_error_notify",$args);
logd_error_notify($errno, $errstr, $errfile, $errline, $backtrace);
}
die();
break;
}
$in_error_handler--;
}
function logd_error_notify($errno, $errstr, $errfile, $errline, $backtrace){
global $session;
$sendto = explode(";",getsetting("notify_address",""));
$howoften = getsetting("notify_every",30);
reset($sendto);
$data = datacache("error_notify",86400);
if (!is_array($data)){
$data = array('firstrun'=>true,'errors'=>array());
}else{
$data['firstrun'] = false;
}
$do_notice = false;
if (!array_key_exists($errstr,$data['errors'])){
$do_notice = true;
}elseif (strtotime("now") - ($data['errors'][$errstr]) > $howoften * 60) {
$do_notice = true;
}
if ($data['firstrun']){
debug("First run, not notifying users.");
}else{
if ($do_notice){
/***
* Set up the mime bits
**/
require_once("sanitize.php");
$notice_text = "This is a multi-part message in MIME format.";
$userstr = "";
if ($session && isset($session['user']['name']) && isset($sesson['user']['acctid'])) {
$userstr = "Error triggered by user " . $session['user']['name'] . " (" . $session['user']['acctid'] . ")\n";
}
$plain_text = "$userstr$errstr in $errfile ($errline)\n".sanitize_html($backtrace);
$html_text = "