31 private static $headersSentCallback =
null;
34 $old = self::$headersSentCallback;
35 self::$headersSentCallback = $callback;
47 static $statusMessage = [
49 101 =>
'Switching Protocols',
54 203 =>
'Non-Authoritative Information',
56 205 =>
'Reset Content',
57 206 =>
'Partial Content',
58 207 =>
'Multi-Status',
59 300 =>
'Multiple Choices',
60 301 =>
'Moved Permanently',
63 304 =>
'Not Modified',
65 307 =>
'Temporary Redirect',
67 401 =>
'Unauthorized',
68 402 =>
'Payment Required',
71 405 =>
'Method Not Allowed',
72 406 =>
'Not Acceptable',
73 407 =>
'Proxy Authentication Required',
74 408 =>
'Request Timeout',
77 411 =>
'Length Required',
78 412 =>
'Precondition Failed',
79 413 =>
'Request Entity Too Large',
80 414 =>
'Request-URI Too Large',
81 415 =>
'Unsupported Media Type',
82 416 =>
'Request Range Not Satisfiable',
83 417 =>
'Expectation Failed',
84 422 =>
'Unprocessable Entity',
86 424 =>
'Failed Dependency',
87 428 =>
'Precondition Required',
88 429 =>
'Too Many Requests',
89 431 =>
'Request Header Fields Too Large',
90 500 =>
'Internal Server Error',
91 501 =>
'Not Implemented',
93 503 =>
'Service Unavailable',
94 504 =>
'Gateway Timeout',
95 505 =>
'HTTP Version Not Supported',
96 507 =>
'Insufficient Storage',
97 511 =>
'Network Authentication Required',
99 return $statusMessage[$code] ??
null;
110 static $version = null;
111 $message = self::getMessage( $code );
112 if ( $message ===
null ) {
113 throw new InvalidArgumentException(
"Unknown HTTP status code $code" );
116 if ( $version ===
null ) {
117 $version = isset( $_SERVER[
'SERVER_PROTOCOL'] ) &&
118 $_SERVER[
'SERVER_PROTOCOL'] ===
'HTTP/1.0' ?
123 return "HTTP/$version $code $message";
133 if ( headers_sent() ) {
134 if ( self::$headersSentCallback ) {
135 ( self::$headersSentCallback )();
144 header( self::getHeader( $code ) );
145 }
catch ( InvalidArgumentException $ex ) {
146 trigger_error(
"Unknown HTTP status code $code", E_USER_WARNING );
static header( $code)
Output an HTTP status code header.
static getHeader( $code)
Construct an HTTP status code header.
static getMessage( $code)
Get the message associated with an HTTP response status code.
static registerHeadersSentCallback(callable $callback)