Source for file Header.php
Documentation is available at Header.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Wolfram Kriesing <wk@visionp.de> |
// | Davey Shafik <davey@php.net> |
// | Michael Wallner <mike@php.net> |
// +----------------------------------------------------------------------+
// $Id: Header.php,v 1.19 2004/06/10 22:02:08 mike Exp $
define('HTTP_HEADER_STATUS_100', '100 Continue');
define('HTTP_HEADER_STATUS_101', '101 Switching Protocols');
define('HTTP_HEADER_STATUS_102', '102 Processing');
define('HTTP_HEADER_STATUS_INFORMATIONAL',1 );
define('HTTP_HEADER_STATUS_200', '200 OK');
define('HTTP_HEADER_STATUS_201', '201 Created');
define('HTTP_HEADER_STATUS_202', '202 Accepted');
define('HTTP_HEADER_STATUS_203', '203 Non-Authoriative Information');
define('HTTP_HEADER_STATUS_204', '204 No Content');
define('HTTP_HEADER_STATUS_205', '205 Reset Content');
define('HTTP_HEADER_STATUS_206', '206 Partial Content');
define('HTTP_HEADER_STATUS_207', '207 Multi-Status');
define('HTTP_HEADER_STATUS_SUCCESSFUL',2 );
define('HTTP_HEADER_STATUS_300', '300 Multiple Choices');
define('HTTP_HEADER_STATUS_301', '301 Moved Permanently');
define('HTTP_HEADER_STATUS_302', '302 Found');
define('HTTP_HEADER_STATUS_303', '303 See Other');
define('HTTP_HEADER_STATUS_304', '304 Not Modified');
define('HTTP_HEADER_STATUS_305', '305 Use Proxy');
define('HTTP_HEADER_STATUS_306', '306 (Unused)');
define('HTTP_HEADER_STATUS_307', '307 Temporary Redirect');
define('HTTP_HEADER_STATUS_REDIRECT',3 );
define('HTTP_HEADER_STATUS_400', '400 Bad Request');
define('HTTP_HEADER_STATUS_401', '401 Unauthorized');
define('HTTP_HEADER_STATUS_402', '402 Payment Granted');
define('HTTP_HEADER_STATUS_403', '403 Forbidden');
define('HTTP_HEADER_STATUS_404', '404 File Not Found');
define('HTTP_HEADER_STATUS_405', '405 Method Not Allowed');
define('HTTP_HEADER_STATUS_406', '406 Not Acceptable');
define('HTTP_HEADER_STATUS_407', '407 Proxy Authentication Required');
define('HTTP_HEADER_STATUS_408', '408 Request Time-out');
define('HTTP_HEADER_STATUS_409', '409 Conflict');
define('HTTP_HEADER_STATUS_410', '410 Gone');
define('HTTP_HEADER_STATUS_411', '411 Length Required');
define('HTTP_HEADER_STATUS_412', '412 Precondition Failed');
define('HTTP_HEADER_STATUS_413', '413 Request Entity Too Large');
define('HTTP_HEADER_STATUS_414', '414 Request-URI Too Large');
define('HTTP_HEADER_STATUS_415', '415 Unsupported Media Type');
define('HTTP_HEADER_STATUS_416', '416 Requested range not satisfiable');
define('HTTP_HEADER_STATUS_417', '417 Expectation Failed');
define('HTTP_HEADER_STATUS_422', '422 Unprocessable Entity');
define('HTTP_HEADER_STATUS_423', '423 Locked');
define('HTTP_HEADER_STATUS_424', '424 Failed Dependency');
define('HTTP_HEADER_STATUS_CLIENT_ERROR',4 );
define('HTTP_HEADER_STATUS_500', '500 Internal Server Error');
define('HTTP_HEADER_STATUS_501', '501 Not Implemented');
define('HTTP_HEADER_STATUS_502', '502 Bad Gateway');
define('HTTP_HEADER_STATUS_503', '503 Service Unavailable');
define('HTTP_HEADER_STATUS_504', '504 Gateway Timeout');
define('HTTP_HEADER_STATUS_505', '505 HTTP Version Not Supported');
define('HTTP_HEADER_STATUS_507', '507 Insufficient Storage');
define('HTTP_HEADER_STATUS_SERVER_ERROR',5 );
* @version $Revision: 1.19 $
* The values that are set as default, are the same as PHP sends by default.
'content-type' => 'text/html',
'cache-control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
var $_httpVersion = '1.0';
* @return object HTTP_Header
if (isset ($_SERVER['SERVER_PROTOCOL'])) {
* @return bool Returns true on success or false if version doesn't
* match 1.0 or 1.1 (note: 1 will result in 1.0)
* @param mixed $version HTTP version, either 1.0 or 1.1
$version = round((float) $version, 1 );
if ($version < 1.0 || $version > 1.1 ) {
$this->_httpVersion = sprintf('%0.1f', $version);
return $this->_httpVersion;
* The default value for the Last-Modified header will be current
* date and atime if $value is omitted.
* @return bool Returns true on success or false if $key was empty or
* $value was not of an scalar type.
* @param string $key The name of the header.
* @param string $value The value of the header.
if (empty ($key) || (isset ($value) && !is_scalar($value))) {
if ($key == 'last-modified') {
$value = HTTP ::Date (time());
$value = HTTP ::Date ($value);
$this->_headers[$key] = $value;
* If $key is omitted, all stored headers will be returned.
* @return mixed Returns string value of the requested header,
* array values of all headers or false if header $key
* @param string $key The name of the header to fetch.
if (!isset ($this->_headers[$key])) {
return $this->_headers[$key];
* Send out the header that you set via setHeader().
* @return bool Returns true on success or false if headers are already
* @param array $keys Headers to (not) send, see $include.
* @param array $include If true only $keys matching headers will be
* sent, if false only header not matching $keys will be
foreach ($this->_headers as $key => $value) {
foreach ($this->_headers as $header => $value) {
header($header . ': '. $value);
* Send out the given HTTP-Status code. Use this for example when you
* want to tell the client this page is cached, then you would call
* @see HTTP_Header_Cache::exitIfCached()
* @return bool Returns true on success or false if headers are already
* @param int $code The status code to send, i.e. 404, 304, 200, etc.
if ($code == (int) $code && defined('HTTP_HEADER_STATUS_'. $code)) {
$code = constant('HTTP_HEADER_STATUS_'. $code);
header('HTTP/'. $this->_httpVersion . ' '. $code);
* Mon, 31 Mar 2003 15:26:34 GMT
* Tue, 15 Nov 1994 12:45:26 GMT
* into a timestamp, strtotime() didn't do it in older versions.
* @return mixed Returns int unix timestamp or false if the date doesn't
* seem to be a valid GMT date.
* @param string $date The GMT date.
null => 0 , 'Jan' => 1 , 'Feb' => 2 , 'Mar' => 3 , 'Apr' => 4 ,
'May' => 5 , 'Jun' => 6 , 'Jul' => 7 , 'Aug' => 8 , 'Sep' => 9 ,
'Oct' => 10 , 'Nov' => 11 , 'Dec' => 12
if (-1 < $timestamp = strToTime ($date)) {
if (!preg_match ('~[^,]*,\s(\d+)\s(\w+)\s(\d+)\s(\d+):(\d+):(\d+).*~',
// [0] => Mon, 31 Mar 2003 15:42:55 GMT
// [1] => 31 [2] => Mar [3] => 2003 [4] => 15 [5] => 42 [6] => 55
return mktime ($m[4 ], $m[5 ], $m[6 ], $months[$m[2 ]], $m[1 ], $m[3 ]);
* This function redirects the client. This is done by issuing a Location
* header and exiting. Additionally to HTTP::redirect() you can also add
* If you dont need parameters to be added, simply use HTTP::redirect()
* otherwise use HTTP_Header::redirect().
* @author Wolfram Kriesing <wk@visionp.de>
* @param string $url The URL to redirect to, if none is given it
* redirects to the current page.
* @param mixed $param Possible values:
* o null (default) - only the session-id will be
* added, but only when trans_sid is enabled.
* o false - no parameters to add
* o true - add the session-id
* o array - of parameter names, if the key is a string
* it's assumed to be name => value, otherwise the
* value is retreived using $GLOBALS['paraName'].
function redirect($url = null , $param = null )
$url = $_SERVER['PHP_SELF'];
if ($param || (!isset ($param) && ini_get('session.use_trans_sid'))) {
foreach ($param as $key => $val) {
$url .= (isset ($purl['query']) ? '&' : '?') . implode('&', $qs);
* @author Davey Shafik <davey@php.net>
* @param int $http_code HTTP Code to check
* Return HTTP Status Code Type
$type = substr($http_code,0 ,1 );
* Return Status Code Message
if (is_int($http_code) && defined('HTTP_HEADER_STATUS_' . $http_code)) {
* Checks if HTTP Status code is Information (1xx)
* Checks if HTTP Status code is Successful (2xx)
* Checks if HTTP Status code is a Redirect (3xx)
* Checks if HTTP Status code is a Client Error (4xx)
* Checks if HTTP Status code is Server Error (5xx)
* Checks if HTTP Status code is Server OR Client Error (4xx or 5xx)
Documentation generated on Mon, 11 Mar 2019 13:51:31 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|