public static function dispatch($status = 200, $body = '', $content_type = 'text/html') { $status_header = sprintf('HTTP/1.1 %s %s', $status, dispatcher::get_status_code_message($status)); header($status_header); header('Content-type: ' . $content_type); if ($body == '') { // create some body messages $message = ''; // this is purely optional, but makes the pages a little nicer to read // for your users. Since you won't likely send a lot of different status codes, // this also shouldn't be too ponderous to maintain switch ($status) { case 401: $message = 'You must be authorized to view this page.'; break; case 404: $message = sprintf('The requested URL %s was not found.', $_SERVER['REQUEST_URI']); break; case 500: $message = 'The server encountered an error processing your request.'; break; case 501: $message = 'The requested method is not implemented.'; break; default: } // servers don't always have a signature turned on (this is an apache directive "ServerSignature On") $signature = ''; if ($_SERVER['SERVER_SIGNATURE'] == '') { $signature = sprintf('%s Server at %s Port %s', $_SERVER['SERVER_SOFTWARE'], $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT']); } else { $signature = $_SERVER['SERVER_SIGNATURE']; } $body = sprintf('<h1>%s</h1><p>%s</p>', dispatcher::get_status_code_message($status), $message); echo $body; exit; } else { // send the body echo $body; exit; } }