note 73773 added to function.set-error-handler

From: Date: Fri, 09 Mar 2007 16:57:03 +0000
Subject: note 73773 added to function.set-error-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-124272@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 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 ---- Server IP: 69.147.83.197 Probable Submitter: 216.62.70.35 ---- Manual Page -- http://www.php.net/manual/en/function.set-error-handler.php Edit -- https://master.php.net/note/edit/73773 Del: integrated -- https://master.php.net/note/delete/73773/integrated Del: useless -- https://master.php.net/note/delete/73773/useless Del: bad code -- https://master.php.net/note/delete/73773/bad+code Del: spam -- https://master.php.net/note/delete/73773/spam Del: non-english -- https://master.php.net/note/delete/73773/non-english Del: in docs -- https://master.php.net/note/delete/73773/in+docs Del: other reasons-- https://master.php.net/note/delete/73773 Reject -- https://master.php.net/note/reject/73773 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124272) next »