468,290 Members | 1,866 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

provide pretty page for fatal errors?

Hi,

Is it possible in PHP to provide a nice pretty page when a fatal error
occurs? (Or any of the errors listed here
http://uk.php.net/manual/en/function...or-handler.php which you
cannot catch).

I have error_reporting turned off as I have a production server - but
that just gives a blank page which is less than good.

Si

Oct 27 '06 #1
1 1378
Simon Kittle schreef:
Is it possible in PHP to provide a nice pretty page when a fatal error
occurs? (Or any of the errors listed here
http://uk.php.net/manual/en/function...or-handler.php which you
cannot catch).

I have error_reporting turned off as I have a production server - but
that just gives a blank page which is less than good.
With these kind of errors, the parsing comes to a dead stop, hence why
you cannot apply user-defined functions to handle them.

This implies that you cannot do anything on the server level to handle
these errors.

Client-side, however, you could use javascript to forward to a new page
or print a message. Example:

<?php

print <<<EOS
<script>
window.onload = function () {
if (!window.ok) {
document.location = 'error.html';
}
}
</script>
EOS;
foo();

print '<script>var ok = 1</script>';

?>

In this case, the call to the undefined foo() function causes a fatal
error, so var ok gets never set and the onload action redirects the user
to error.html

When foo() is defined, var ok will be printed and the onload function
will do nothing.

HTH;
JW
Oct 27 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Tim Tyler | last post: by
3 posts views Thread by Joel D. Kraft | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.