PDA

Click to See Complete Forum and Search --> : Error Handler Class


visualAd
Aug 13th, 2004, 02:42 AM
I just finished creating an error handling class in PHP. The source code is here:

http://www.sccode.com/projects/filemanager/src/error.phps

The documentation here:

http://www.sccode.com/projects/filemanager/src/error_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
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 = 'me@mydomain.com';
$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>');
}
?>

ober0330
Aug 13th, 2004, 07:29 AM
I've been meaning to write something like this. Thanks for doing the work for me. :D

visualAd
Aug 18th, 2004, 11:11 AM
Just updated the class. It had a small bug in it. :bigyello:

dclamp
Jul 5th, 2008, 06:54 PM
fail. 404 Error ;)



edit:
along with this:
http://www.sccode.com/projects/filemanager/src/session_handler.html

visualAd
Jul 6th, 2008, 02:39 AM
Fixed.

dclamp
Jul 6th, 2008, 01:14 PM
ok great thanks! I might use it on a project that i am working on.

the182guy
Jul 6th, 2008, 02:28 PM
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:

dclamp
Jul 6th, 2008, 03:05 PM
for admin_email can i include more then one email?

visualAd
Jul 6th, 2008, 03:17 PM
It uses the PHP mail function, so there should not be an issue if you separate the addresses with a comma.

dclamp
Jul 6th, 2008, 03:31 PM
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.

visualAd
Jul 6th, 2008, 03:45 PM
I am the webmaster. Done you remember?

dclamp
Jul 6th, 2008, 04:02 PM
silly me :)