Using Linux/Apache/PHP7, I want to display all error messages gracefully. I have my .htaccess file with the following:
ErrorDocument 400 /errors/error.php
ErrorDocument 401 /errors/error.php
ErrorDocument 403 /errors/error.php
ErrorDocument 404 /errors/error.php
ErrorDocument 500 /errors/error.php
ErrorDocument 502 /errors/error.php
ErrorDocument 504 /errors/error.php
...which points to a error.php page with the following:
$status = $_SERVER['REDIRECT_STATUS'];
$codes = array(
400 => array('400 Bad Request', 'The request cannot be fulfilled due to bad syntax.'),
403 => array('403 Forbidden', 'The server has refused to fulfil your request.'),
404 => array('404 Not Found', 'The page you requested was not found on this server.'),
405 => array('405 Method Not Allowed', 'The method specified in the request is not allowed for the specified resource.'),
408 => array('408 Request Timeout', 'Your browser failed to send a request in the time allowed by the server.'),
500 => array('500 Internal Server Error', 'The request was unsuccessful due to an unexpected condition encountered by the server.'),
502 => array('502 Bad Gateway', 'The server received an invalid response while trying to carry out the request.'),
504 => array('504 Gateway Timeout', 'The upstream server failed to send a request in the time allowed by the server.'),
);
$title = $codes[$status][0];
$message = $codes[$status][1];
if ($title == false || strlen($status) != 3) {
$message = 'Please supply a valid HTTP status code.';
}
echo '<h1>Hold up! '.$title.' detected</h1>
<p>'.$message.'</p>';
The 404 function seems to work just fine, but any php error like a typo in a function name still displays as a white screen with standard php error messages. Even an intentional typo in the .htaccess file produces a generic 500 error, but doesn't use the error.php page I established for this purpose.
What I'd like to do also is display the php error details for me, but hide the details for users, even when in production mode.