|
Posted by Janwillem Borleffs on 10/27/06 15:06
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.set-error-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
[Back to original message]
|