amb99 Posted February 1, 2007 Share Posted February 1, 2007 Hi, My current error reporting is set to: error_reporting (E_ERROR | E_WARNING | E_PARSE); Is there a way to use a default html page whenever any errors are encountered? (Instead of displaying the actual message of X error on X line for X script, this I would restrict to myself only, and for everyone else preferably would be only able to see the default page.) Thank you for any help that you can provide. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted February 1, 2007 Share Posted February 1, 2007 You could do something like this: <?php function custom_error_handler($errno, $errstr, $errfile, $errline, $errcontext) { echo <<<EOF <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"> <head> <title>Application error</title> </head> <body> <h1>Application error</h1> <p>We're sorry, but we encountered an error in the script and are therefore unable to continue. We apologize for an inconvenience this may have caused.</p> </body> </html> EOF; die(); } set_error_handler("custom_error_handler"); ?> With that you are also able to make some logging functions. Quote Link to comment Share on other sites More sharing options...
amb99 Posted February 1, 2007 Author Share Posted February 1, 2007 I've added that function and am using the code below, which is included in every script. if ($user_ip == "x.x.x.x") { error_reporting(E_ERROR | E_WARNING | E_PARSE); } else { set_error_handler("custom_error_handler"); } The problem is that the set_error_handler calls that function regardless if whether or not there is an error. Whereas, error_reporting only displays when an error has actually occured. So now I'm just trying to figure out how to write it so that set_error_handler is only called when an error actually occurs. I've tried adding braces within the custom_error_handler function you suggested: if (error_reporting()) { } but that did not work. It still echo's even when there is no error occuring. So I tried: if (error_reporting(E_ERROR | E_WARNING | E_PARSE)) { } Still no luck. I took a peek at error_reporting(E_ALL); and I do see some minor variable problems which might be the reason why when doing set_error_handler it immediately echos? Though I'm unsure. Is there a sure way to only display that default page when and only when an error has actually occured, just like how error_reporting(E_ERROR | E_WARNING | E_PARSE) works? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 1, 2007 Share Posted February 1, 2007 I think the error handler function needs to be more like the ones here: http://us2.php.net/set_error_handler Try starting with what they have and then just add HTML. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.