<? // Decide what errors to report: error_reporting (E_ERROR | E_WARNING | E_NOTICE); // Webmaster email and error page url: $Wmemail = '[email protected]'; $ErrorPage = 'http://www.ursite.com/error.html'; // This function will check the error type: function MailErrorHandler($errno, $errstr, $errfile='?', $errline= '?') { global $Wmemail, $ErrorPage; if (($errno & error_reporting()) == 0) return; $err = ''; switch($errno) { case E_ERROR: $err = 'FATAL'; break; case E_WARNING: $err = 'ERROR'; break; case E_NOTICE: return; } // Send the error details via email: mail($Wmemail, "PHP: $errfile, $errline", "$errfile, Line $errline\n$err($errno)\n$errstr"); // Redirect to the error page: print '<META HTTP-EQUIV="Refresh" CONTENT="0;url='.$ErrorPage.'">'; die(); } set_error_handler('MailErrorHandler'); ?>
It is commented so that the code explains it's self, however I will explain it alittle bit so this isnt just a code dump.
<? // Decide what errors to report: error_reporting (E_ERROR | E_WARNING | E_NOTICE); // Webmaster email and error page url: $Wmemail = '[email protected]'; $ErrorPage = 'http://www.ursite.com/error.html'; // This function will check the error type: function MailErrorHandler($errno, $errstr, $errfile='?', $errline= '?') {
Ok this part gets your e-mail address and the url to your error page so it can redirect if the user encounters an error. Then it gets all the details of your error so it can email it to you.
global $Wmemail, $ErrorPage; if (($errno & error_reporting()) == 0) return; $err = ''; switch($errno) { case E_ERROR: $err = 'FATAL'; break; case E_WARNING: $err = 'ERROR'; break; case E_NOTICE: return; }
Gets the error details and the severity then gets ready to redirect to the error page url.
// Send the error details via email: mail($Wmemail, "PHP: $errfile, $errline", "$errfile, Line $errline\n$err($errno)\n$errstr"); // Redirect to the error page: print '<META HTTP-EQUIV="Refresh" CONTENT="0;url='.$ErrorPage.'">'; die(); } set_error_handler('MailErrorHandler'); ?>
This part actually sends the email to your inbox, includes the details of the error, the page url the output the error, what line the error was caused on and all that jazz. Then it redirects the user to the error page.
Well that is all, hope you enjoyed this, and I hope that it benefits you all in some way or another.