/** * * @param int $status * @param string $body * @param string $content_type * @param string $charset */ public static function sendResponse($status = 200, $body = '', $content_type = 'text/', $charset = 'utf-8') { $status_header = 'HTTP/1.1 ' . $status . ' ' . Rest::getStatusCodeMessage($status); header($status_header); header('Content-type: ' . $content_type . '; charset="' . $charset . '";'); if ($body != '' && $status == 200) { print $body; exit; } else { $message = ''; switch ($status) { case 401: $message = 'Vous devez être autorisé à afficher cette page.'; break; case 404: $message = 'L\'url demandé : ' . $_SERVER['REQUEST_URI'] . ' n\'a pas été trouvé.'; break; case 500: $message = 'Le serveur a rencontré une erreur lors du traitement de votre demande.'; break; case 501: $message = 'La méthode demandée n\'est pas implémentée.'; break; } $signature = $_SERVER['SERVER_SIGNATURE'] == '' ? $_SERVER['SERVER_SOFTWARE'] . ' Serveur à ' . $_SERVER['SERVER_NAME'] . ' Port ' . $_SERVER['SERVER_PORT'] : $_SERVER['SERVER_SIGNATURE']; $body = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'; $body .= '<html>'; $body .= ' <head>'; $body .= ' <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'; $body .= ' <title>' . $status . ' ' . Rest::getStatusCodeMessage($status) . '</title>'; $body .= ' </head>'; $body .= ' <body>'; $body .= ' <h1>' . Rest::getStatusCodeMessage($status) . '</h1>'; $body .= ' <p>' . $message . '</p>'; $body .= ' <hr />'; $body .= ' <address>' . $signature . '</address>'; $body .= ' </body>'; $body .= '</html>'; print $body; exit; } }