user726049
user726049

Reputation:

Log errors, and instead of displaying them, show a 500 Error Page in PHP

I am trying to achieve the following for my site; first of all, this is for production mode only. My goal is to keep all errors hidden from the visitor, but log them and display a 500 Internal Server Error Page.

The part of hiding those errors is easy - the only thing is to turn off display_errors.

Right now, I am using a custom written function as error handler. It basically just sends a 500 Error Page, but neither that seems to work. Here is the function:

function error_handler($errno, $errstr) { header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500); die(); }

Because of this, another error occurs - the errors don't get logged because I use die() at the end of this function.

Any idea how this might work?

Upvotes: 3

Views: 321

Answers (1)

Daniel
Daniel

Reputation: 3806

Have a look at the error_log function.

Upvotes: 1

Related Questions