Http.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. Lib::loadClass('HttpException');
  3. /**
  4. * Http::sendHeaderByCode(404) -> header('HTTP/1.0 404 Not Found');
  5. */
  6. class Http {
  7. public static $statusTexts = array(
  8. 100 => 'Continue',
  9. 101 => 'Switching Protocols',
  10. 102 => 'Processing',
  11. 200 => 'OK',
  12. 201 => 'Created',
  13. 202 => 'Accepted',
  14. 203 => 'Non-Authoritative Information',
  15. 204 => 'No Content',
  16. 205 => 'Reset Content',
  17. 206 => 'Partial Content',
  18. 207 => 'Multi-Status',
  19. 208 => 'Already Reported',
  20. 226 => 'IM Used',
  21. 300 => 'Multiple Choices',
  22. 301 => 'Moved Permanently',
  23. 302 => 'Found',
  24. 303 => 'See Other',
  25. 304 => 'Not Modified',
  26. 305 => 'Use Proxy',
  27. 306 => 'Reserved',
  28. 307 => 'Temporary Redirect',
  29. 308 => 'Permanent Redirect',
  30. 400 => 'Bad Request',
  31. 401 => 'Unauthorized',
  32. 402 => 'Payment Required',
  33. 403 => 'Forbidden',
  34. 404 => 'Not Found',
  35. 405 => 'Method Not Allowed',
  36. 406 => 'Not Acceptable',
  37. 407 => 'Proxy Authentication Required',
  38. 408 => 'Request Timeout',
  39. 409 => 'Conflict',
  40. 410 => 'Gone',
  41. 411 => 'Length Required',
  42. 412 => 'Precondition Failed',
  43. 413 => 'Request Entity Too Large',
  44. 414 => 'Request-URI Too Long',
  45. 415 => 'Unsupported Media Type',
  46. 416 => 'Requested Range Not Satisfiable',
  47. 417 => 'Expectation Failed',
  48. 418 => 'I\'m a teapot',
  49. 422 => 'Unprocessable Entity',
  50. 423 => 'Locked',
  51. 424 => 'Failed Dependency',
  52. 425 => 'Reserved for WebDAV advanced collections expired proposal',
  53. 426 => 'Upgrade Required',
  54. 428 => 'Precondition Required',
  55. 429 => 'Too Many Requests',
  56. 431 => 'Request Header Fields Too Large',
  57. 500 => 'Internal Server Error',
  58. 501 => 'Not Implemented',
  59. 502 => 'Bad Gateway',
  60. 503 => 'Service Unavailable',
  61. 504 => 'Gateway Timeout',
  62. 505 => 'HTTP Version Not Supported',
  63. 506 => 'Variant Also Negotiates (Experimental)',
  64. 507 => 'Insufficient Storage',
  65. 508 => 'Loop Detected',
  66. 510 => 'Not Extended',
  67. 511 => 'Network Authentication Required'
  68. );
  69. /**
  70. * @param $code
  71. *
  72. * examples:
  73. * 404 -> HTTP/1.0 404 Not Found
  74. * 403 -> HTTP/1.0 403 Forbidden
  75. */
  76. public static function sendHeaderByCode($code) {
  77. if (array_key_exists($code, self::$statusTexts)) {
  78. header("HTTP/1.0 {$code} " . self::$statusTexts[$code]);
  79. }
  80. }
  81. }