100 lines
3.0 KiB
PHP
100 lines
3.0 KiB
PHP
<?php
|
|
/**
|
|
* $Id: ErrorHandler.php 959 2008-07-29 06:34:41Z pawy $
|
|
* Obsluga bledow
|
|
*
|
|
* @param integer $errno
|
|
* @param string $errstr
|
|
* @param string $errfile
|
|
* @param integer $errline
|
|
* @return unknown
|
|
*/
|
|
function AppErrorHandler($errno, $errstr, $errfile, $errline) {
|
|
|
|
if(!(error_reporting() & $errno)) {
|
|
return true;
|
|
}
|
|
|
|
switch ($errno) {
|
|
|
|
case E_STRICT:
|
|
case E_DEPRECATED:
|
|
case E_USER_DEPRECATED:
|
|
break;
|
|
|
|
|
|
case E_NOTICE:
|
|
MFLog::Warn("Line: ".$errline." File: ".$errfile." Message: ".$errstr." Referer: ".getenv('HTTP_REFERER'));
|
|
|
|
if(Config::Get('ERROR_REDIRECT') != 'true') {
|
|
echo "<span style=\"color: red;\">Unknown error type: [$errno] $errstr<br /></span>\n";
|
|
echo $errfile.':'.$errline;
|
|
}
|
|
break;
|
|
|
|
|
|
default:
|
|
if(!preg_match('/mysql_connect()/', $errstr)) {
|
|
MFLog::Error("Line: ".$errline." File: ".$errfile." Message: ".$errstr." Referer: ".getenv('HTTP_REFERER'));
|
|
|
|
if(Config::Get('ERROR_REDIRECT') == 'true') {
|
|
// Redirect-loop guard (2026-05-20): log root cause and route with trailing
|
|
// slash so mod_dir doesn't issue a https->http degrading 301.
|
|
error_log("ErrorHandler redirect: [$errno] $errstr at $errfile:$errline (REQUEST_URI=" . ($_SERVER['REQUEST_URI'] ?? '-') . ")");
|
|
if(getenv('HTTP_REFERER')==Config::Get('URL_MAIN')) {
|
|
Header("Location: ".Config::Get('URL_MAIN')."/error.html");
|
|
} else {
|
|
header("HTTP/1.0 302 Moved Temporarily");
|
|
Header("Location: ".rtrim(Config::Get('URL_MAIN'), '/')."/");
|
|
}
|
|
} else {
|
|
echo "<span style=\"color: red;\">Unknown error type: [$errno] $errstr<br /></span>\n";
|
|
echo $errfile.':'.$errline;
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/* Don't execute PHP internal error handler */
|
|
return true;
|
|
}
|
|
|
|
set_error_handler("AppErrorHandler");
|
|
|
|
|
|
/**
|
|
* Obsluguje wyjatki
|
|
*
|
|
* @param Exception $exception
|
|
*/
|
|
function ExceptionHandler($exception) {
|
|
|
|
|
|
|
|
MFLog::Error("Line: ".$exception->getLine()." Message: ".$exception->getMessage()." Referer: ".getenv('HTTP_REFERER'));
|
|
|
|
if(ERROR_REDIRECT == 'true') {
|
|
// Redirect-loop guard (2026-05-20): log root cause and route with trailing slash.
|
|
error_log("ExceptionHandler redirect: " . $exception->getMessage() . " at " . $exception->getFile() . ":" . $exception->getLine() . " (REQUEST_URI=" . ($_SERVER['REQUEST_URI'] ?? '-') . ")");
|
|
if(getenv('HTTP_REFERER')==Config::Get('URL_MAIN')) {
|
|
Header("Location: ".Config::Get('URL_MAIN')."/error.html");
|
|
} else {
|
|
header("HTTP/1.0 302 Moved Temporarily");
|
|
Header("Location: ".rtrim(Config::Get('URL_MAIN'), '/')."/");
|
|
}
|
|
} else {
|
|
echo "<br /><span style=\"color: red;\">Nie obsluzony wyjatek: " , $exception->getMessage(), "</span>\n".getenv('HTTP_REFERER');
|
|
echo $exception;
|
|
}
|
|
|
|
}
|
|
|
|
set_exception_handler('ExceptionHandler');
|
|
if(Config::Get('ERROR_REDIRECT') == true) {
|
|
ini_set('html_errors',false);
|
|
ini_set('error_prepend_string','<html><head><META http-equiv="refresh" content="0;URL='.Config::Get('FATAL_ERROR_URL').'"></head></html>');
|
|
//ini_set('error_append_string','"></head></html>');
|
|
}
|
|
?>
|