note 73773 deleted from function.set-error-handler by philip
| From: | philip@php.net | Date: | Fri, 09 Mar 2007 19:49:20 +0000 |
| Subject: | note 73773 deleted from function.set-error-handler by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-124280@lists.php.net to get a copy of this message | ||
Note Submitter: bitagenda at gmail dot com
----
A simple and effective way to catch Fatal errors.
From here you can go forward with your own ideas and elaborate a detailed error report.
The principle is simple and ready to test on your system
Fatal errors are not currently catched and you should have display errors off in production sites,
but may be you need to test the system so you want a fast an easy way to see fatal errors in your
currently running site, without the users seeing those Fatal errors as recomended.
You must have this function
function catchFatalErrors($p_OnOff='On'){
ini_set('display_errors','On');
$phperror='><div id="phperror" style="display:none">';
ini_set('error_prepend_string',$phperror);
$phperror='</div>><form name="catcher" action="/sos.php"
method="post" ><input type="hidden" name="fatal"
value=""></form><script>document.catcher.fatal.value =
document.getElementById("phperror").innerHTML;
document.catcher.submit();</script>';
ini_set('error_append_string',$phperror);
}
Now activate your fatal error catcher
catchFatalErrors();
Just to test write this inexistent function
Bitagenda();
That's all. As you can see there will be a form posted with action="/sos.php", of
course you can name this page at your liking, in this case is at the site's root.
Have ready your page sos.php, and elaborate on that. Of course change the mail address to yours,and
display a message to the user at your liking.
<?php
if (isset($_POST['fatal'])){
error_log($_POST['fatal'],1,'bitagenda@gmail.com');
}
?>
"System Out of Service. Thanks for waiting."
The other fact about this handler is that even if you do not redirect the Fatal Error is that
prepending
><div style="display:none">
and appending
</div>
Then writting yor personal message
" Sorry, fatal bug."
Will hide the fatal error message from the user, but still can be seen using view/source code