Errorpages/php/messages.php

33 lines
1.1 KiB
PHP
Raw Normal View History

2023-10-16 12:53:24 +00:00
<?php
const RESPONSES = [
// Currently supported responses
// See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses
401 => "You are no authorized to access the resource",
404 => "The requested resource couldn't be found",
403 => "Access to the resource was denied for the server",
405 => "Method not supported by the server",
407 => "You are no authorized to access the resource",
408 => "Request timed out",
500 => "The server encountered an internal error",
501 => "Method not supported by the server",
502 => "Requested endpoint encountered an error",
503 => "Service is currently unavailable",
504 => "Requested endpoint is unreachable",
511 => "Requested endpoint requires authentication for proxy",
];
function get_status_message($uri): array
{
$status = "501";
$message = "The received status is unsupported by this server: `" . substr($uri, 0, 10) . "`";
$code = intval(trim(str_replace("/", "", $uri)));
if (key_exists($code, RESPONSES)) {
$status = (string) $code;
$message = RESPONSES[$code];
}
return [$status, $message];
}