Skip to content

Instantly share code, notes, and snippets.

@Abbe98
Created August 4, 2013 13:51
Show Gist options
  • Save Abbe98/6150376 to your computer and use it in GitHub Desktop.
Save Abbe98/6150376 to your computer and use it in GitHub Desktop.
A PHP template for dealing with any sort of error, if you want to keep it simple. ErrorDocument: 400, 401, 403, 404, 405, 408, 414, 500, 502 and 504.
<?php
$status=$_SERVER['REDIRECT_STATUS'];
$codes=array(
400 => array('400 Bad Request', 'The request cannot be fulfilled due to bad syntax.'),
401 => array('401 Login Error', 'It appears that the password and/or user-name you entered was incorrect.'),
403 => array('403 Forbidden', 'Sorry, employees and staff only.'),
404 => array('404 Missing', 'We\'re sorry, but the page you\'re looking for is missing, hiding, or maybe it moved somewhere else and forgot to tell you.'),
405 => array('405 Method Not Allowed', 'The method specified in the Request-Line 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.'),
414 => array('414 URL To Long', 'The URL you entered is longer than the maximum length.'),
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 from the upstream server while trying to fulfill the request.'),
504 => array('504 Gateway Timeout', 'The upstream server failed to send a request in the time allowed by the server.'),
);
$errortitle=$codes[$status][0];
$message=$codes[$status][1];
if($errortitle==false){
$errortitle="Unknown Error";
$message="An unknown error has occurred.";
}
?>
<!doctype html>
<html>
<head>
<title><?php echo("$errortitle");?></title>
<meta charset="utf-8">
</head>
<body>
<!-- Insert headers here. -->
<?php
echo('<h1>'.$errortitle.'</h1>');
echo('<p>'.$message.'</p>');
?>
<!-- Insert footers here. -->
</body>
</html>
@wolfferine
Copy link

Hi,

I am new to this, I know that an .htaccess needs to have a reference to the error page:
But it's unclear to me how to use this example.
would you be so kind and help me out.

Appreciate your kindness and help!
Regards

Charles Wolff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment