3 ms·
You can't capture the output buffer on a fatal error; the script just aborts. You do have to wait till the end of your script to write your output otherwise th
by wvenable 17y ago
You can't capture the output buffer on a fatal error; the script just aborts. You do have to wait till the end of your script to write your output otherwise this doesn't work very well but here is some (simplified) code:
$errorTemplate = file_get_contents("errortemplate.html");
$templates = explode('%error%', $text, 2);
ini_set('error_prepend_string', $templates[0]);
ini_set('error_append_string', $templates[1]);
ini_set('html_errors', '0');
The errortemplate.html file is a static HTML file that can contain anything you want. Ours is themed up just like any other page on our website. When a fatal error is triggered, the text %error% will be replaced with the fatal error text. We place that into a form using a hidden textarea so our users can submit it to us.
<textarea style="display: none;">%error%</textarea>
The server log will contain the fatal error, so you don't care about users submitting it you can just wrap it in a comment.
<!-- %error% -->
And that's all there is to it.