From e02a16d7ac2dea3203a27d7dcfc7b44b41b1d068 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Sun, 28 Jun 2015 01:35:38 +0200 Subject: [PATCH] ErrorHandler --- code/errorHandler.php | 57 +++++++++++++++++++++++++++++++++++++++++++ index.php | 1 + 2 files changed, 58 insertions(+) create mode 100644 code/errorHandler.php diff --git a/code/errorHandler.php b/code/errorHandler.php new file mode 100644 index 0000000..b4ee721 --- /dev/null +++ b/code/errorHandler.php @@ -0,0 +1,57 @@ + "Error", + 2 => "Warning", + 4 => "Parsing Error", + 8 => "Notice", + 16 => "Core Error", + 32 => "Core Warning", + 64 => "Compile Error", + 128 => "Compile Warning", + 256 => "User Error", + 512 => "User Warning", + 1024 => "User Notice", + 2048 => "Strict", + 4096 => "Recoverable error", + 8192 => "Deprecated"); + $errLevel=$errorLevels[$errno]; + + # Log the error to the error file + $errorFile=fopen($strErrorsFile,"a"); + if($errorFile!=false){ + fputs($errorFile,"\"$time\",\"$filename:$linenum\",\"($errno $errLevel) $errmsg\"\n"); + fclose($errorFile); + }else{ + echo("\"$time\",\"$filename:$linenum\",\"($errno $errLevel) $errmsg\"\n"); + } + + if($errno!=2 && $errno!=8 && + $errno!=32 && $errno!=128 && + $errno!=512 && $errno!=1024 && + $errno!=8192) + { + # Terminate on fatal errors + die("A fatal error has occurred. Script execution has been aborted"); + } +} + +register_shutdown_function("customError"); +function customError(){ + $arrStrErrorInfo = error_get_last(); + if($arrStrErrorInfo!=null){ + userErrorHandler( + $arrStrErrorInfo["type"], + $arrStrErrorInfo["message"], + $arrStrErrorInfo["file"], + $arrStrErrorInfo["line"], + null); + } +} \ No newline at end of file diff --git a/index.php b/index.php index 21d21df..4f53378 100644 --- a/index.php +++ b/index.php @@ -7,6 +7,7 @@

Scans