Jump to content

error_reporting custom message?


amb99

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.