-
Error Handler Class
I just finished creating an error handling class in PHP. The source code is here:
http://www.sccode.com/projects/filem...src/error.phps
The documentation here:
http://www.sccode.com/projects/filem...r_handler.html
Feel free to use it if you like it and if you have any comments or suggestions, please let me know. Here's a quick code snippet demonstrating its use:
PHP Code:
<?php
include_once 'error.php';
$err = &new error;
$err->logpath = 'myerror.log';
$err->fatal_error_function = Array('friendly_exit');
$err->email_on_errors = true;
$err->email_send = 2;
$err->admin_email = '[email protected]';
$err->email_subject = 'My Custom Error Script';
/* this will produce a notice */
echo ($undefiend);
echo ('this will be seen');
/* start an output buffer */
ob_start();
/* so will this */
$defined = hello;
echo ('you will never see this');
/* this will produce a warning */
fputs($none, 'error');
/* this will produce a fatal error and end the script */
trigger_error('This is a fatal error. Bye bye.', E_USER_ERROR);
function friendly_exit()
{
/* clear the current ouput buffer (if any)*/
if (ob_get_level() >= 1) ob_end_clean();
echo ('<h3>Error</h3>');
echo ('<p>I\\'m sorry, this application has had to terminate. Our maintainance team are aware of the problem and ');
echo ('are working to rectify it as soon as possible.</p>');
}
?>
-
I've been meaning to write something like this. Thanks for doing the work for me. :D
-
Just updated the class. It had a small bug in it. :bigyello:
-
Re: Error Handler Class
-
Re: Error Handler Class
-
Re: Error Handler Class
ok great thanks! I might use it on a project that i am working on.
-
Re: Error Handler Class
Might be a nice idea to have a switch so that if on, when the email is sent, include the POST and GET vars, this would help identify the cause of the error, and also to catch people trying to hack it.:thumb:
-
Re: Error Handler Class
for admin_email can i include more then one email?
-
Re: Error Handler Class
It uses the PHP mail function, so there should not be an issue if you separate the addresses with a comma.
-
Re: Error Handler Class
ok i will try. The reason is i would like to have the script send an email to ME and then to the webmaster, who ever that is.
-
Re: Error Handler Class
I am the webmaster. Done you remember?
-
Re: Error Handler Class