From a24329d817c8980a540b020fbbd1be52e1766d32 Mon Sep 17 00:00:00 2001 From: Greg Roach Date: Sun, 27 Apr 2014 09:21:36 +0100 Subject: Missing change in previous commit --- includes/session.php | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/includes/session.php b/includes/session.php index 4559e8d3b1..4456237bec 100755 --- a/includes/session.php +++ b/includes/session.php @@ -203,7 +203,51 @@ require WT_ROOT.'includes/functions/functions_date.php'; require WT_ROOT.'includes/functions/functions_charts.php'; require WT_ROOT.'includes/functions/functions_utf-8.php'; -set_error_handler('wt_error_handler'); +// Set a custom error handler +set_error_handler(function ($errno, $errstr, $errfile, $errline) { + if ((error_reporting() > 0)&&($errno<2048)) { + if (WT_ERROR_LEVEL==0) { + return; + } + $fmt_msg="
ERROR {$errno}: {$errstr}
"; + $log_msg="ERROR {$errno}: {$errstr};"; + // Although debug_backtrace should always exist in PHP5, without this check, PHP sometimes crashes. + // Possibly calling it generates an error, which causes infinite recursion?? + if ($errno < 16 && function_exists("debug_backtrace") && strstr($errstr, "headers already sent by") === false) { + $backtrace = debug_backtrace(); + $num = count($backtrace); + if (WT_ERROR_LEVEL == 1) { + $num = 1; + } + for ($i = 0; $i < $num; $i++) { + if ($i === 0) { + $fmt_msg .= "0 Error occurred on "; + $log_msg .= "\n0 Error occurred on "; + } else { + $fmt_msg .= "{$i} called from "; + $log_msg .= "\n{$i} called from "; + } + if (isset($backtrace[$i]["line"]) && isset($backtrace[$i]["file"])) { + $fmt_msg .= "line {$backtrace[$i]['line']} of file ".basename($backtrace[$i]['file']).""; + $log_msg .= "line {$backtrace[$i]['line']} of file ".basename($backtrace[$i]['file']); + } + if ($i<$num-1) { + $fmt_msg .= " in function ".$backtrace[$i+1]['function'].""; + $log_msg .= " in function ".$backtrace[$i+1]['function']; + } + $fmt_msg .= "
"; + } + } + echo $fmt_msg; + if (function_exists('AddToLog')) { + AddToLog($log_msg, 'error'); + } + if ($errno == 1) { + die(); + } + } + return false; +}); // Load our configuration file, so we can connect to the database if (file_exists(WT_ROOT.'data/config.ini.php')) { -- cgit v1.3