<?php
function sendstatus($code,$string) {
	header("Status: $code $string");
	header("HTTP/1.x $code $string");
}

global $httperrortitle, $httperrormessage;

$known_http_errors = array(
400 => array("Bad request",
"Your web browser performed a request this server could not understand.  There is also the possibility that you are a (sadly unsuccessful) hacker, trying to do nasty things."),
401 => array("Unauthorized",
"The page you were trying to load requires authorization."),
403 => array("Forbidden",
"The file you were trying to access is off-limits for this server."),
404 => array("Resource not found",
"The page you were trying to access cannot be found."),
405 => array("Method not allowed",
"The HTTP method you requested is not allowed for this resource"),
408 => array("Request timed out",
"The server closed the network connection because the browser didn't finish the request within the specified time."),
410 => array("No longer at this address",
"The requested URL is no longer available on this server and there is no forwarding address."),
411 => array("Bad Content-Length",
"The issued request requires a valid Content-Length header."),
412 => array("Precondition failed",
"The precondition on the request for the URL failed positive evaluation."),
413 => array("Request entity too large",
"The requested method does not allow the data transmitted, or the data volume exceeds the capacity limit."),
414 => array("Submitted URI too large",
"The length of the requested URL exceeds the capacity limit for this server. The request cannot be processed."),
415 => array("Unsupported media type",
"The server does not support the media type transmitted in the request."),
500 => array("Internal server error",
"An unknown error took place while generating the page you requested."),
501 => array("Cannot process request",
" The server does not support the action requested by the browser."),
502 => array("Bad gateway",
"The proxy server received an invalid response from an upstream server."),
503 => array("Service unavailable",
"This service is temporarily disabled due to technical difficulties."),
506 => array("Variant also varies",
"A variant for the requested entity is itself a negotiable resource.  Access not possible.")
);

if (!isset($_GET["httperror"])) { # to cope with the fact that wordpress itself won't set httperror
	$errorcode = 404;
	$errorname = $known_http_errors[$errorcode][0];
	$httperrormessage = $known_http_errors[$errorcode][1];
}
elseif (array_key_exists(intval($_GET["httperror"]),$known_http_errors)) {
	$errorcode = intval($_GET["httperror"]);
	$errorname = $known_http_errors[$errorcode][0];
	$httperrormessage = $known_http_errors[$errorcode][1];
}else {
	$errorcode = intval($_GET["httperror"]); if (!$errorcode) $errorcode = 500;
	$errorname = "Error $errorcode"; /* generic error message */
	$httperrormessage = "The web server issued an error $errorcode.";
}
if ($errorname == "Error $errorcode") $httperrortitle = "HTTP error $errorcode"; /* generic error message */
else $httperrortitle = "$errorname"; /*specific error message */

$httperrormessage = "<p>$httperrormessage</p>";
$httperrormessage .= "<p>HTTP error $errorcode.</p>";

sendstatus($errorcode,$errorname);

// FIXME i should develop a utility class just like information but with an error icon, to use instead of p class="information" down below.
?><?php get_header(); ?>

	<div id="content">

		<h1 class="pagetitle"><?php echo $httperrortitle; ?></h1>
		<div class="information"><?php echo $httperrormessage; ?></div>

	</div>

<?php get_sidebar(); ?>

<?php get_footer(); ?>