note 73759 modified in function.error-reporting by danbrown
| From: | danbrown@php.net | Date: | Fri, 24 Oct 2008 18:35:51 +0000 |
| Subject: | note 73759 modified in function.error-reporting by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145704@lists.php.net to get a copy of this message | ||
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
<?php
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
<?php
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, 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 will be visible in the browsers soure code
view.
What happens if you redirect the page before displaying the error? I don´t know, have not tested,
but at least you could do it to alert you that a fatal error exists and possibly the fatal error is
not displayed (leading to security and at the same time catching the fatal error). Then you could
activate this error handler with post-redirection to see what's going on.
;o)
Bitagenda
--was--
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, 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 will be visible in the browsers soure code
view.
What happens if you redirect the page before displaying the error? I don´t know, have not tested,
but at least you could do it to alert you that a fatal error exists and possibly the fatal error is
not displayed (leading to security and at the same time catching the fatal error). Then you could
activate this error handler with post-redirection to see what's going on.
;o)
Bitagenda
http://php.net/manual/en/function.error-reporting.php