header.php.tmp
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· TMP 代码 · 共 532 行 · 第 1/2 页
TMP
532 行
foreach ($this->_headers as $header => $value) { header($header .': '. $value); } } return true; } /** * Send Satus Code * * 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 * sendStatusCode(304). * * @see HTTP_Header_Cache::exitIfCached() * * @access public * @return bool Returns true on success or false if headers are already * sent. * @param int $code The status code to send, i.e. 404, 304, 200, etc. */ function sendStatusCode($code) { if (headers_sent()) { return false; } if ($code == (int) $code && defined('HTTP_HEADER_STATUS_'. $code)) { $code = constant('HTTP_HEADER_STATUS_'. $code); } if (strncasecmp(PHP_SAPI, 'cgi', 3)) { header('HTTP/'. $this->_httpVersion .' '. $code); } else { header('Status: '. $code); } return true; } /** * Date to Timestamp * * Converts dates like * 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. * * @deprecated Use PHPs strtotime() instead. * @access public * @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. */ function dateToTimestamp($date) { static $months = array( 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)) { return $timestamp; } if (!preg_match('~[^,]*,\s(\d+)\s(\w+)\s(\d+)\s(\d+):(\d+):(\d+).*~', $date, $m)) { return false; } // [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]); } /** * Redirect * * This function redirects the client. This is done by issuing a Location * header and exiting. Additionally to HTTP::redirect() you can also add * parameters to the url. * * If you dont need parameters to be added, simply use HTTP::redirect() * otherwise use HTTP_Header::redirect(). * * @see HTTP::redirect() * @author Wolfram Kriesing <wk@visionp.de> * @access public * @return void * @param string $url The URL to redirect to, if none is given it * redirects to the current page. * @param array $param Array of query string parameters to add; usually * a set of key => value pairs; if an array entry consists * only of an value it is used as key and the respective * value is fetched from $GLOBALS[$value] * @param bool $session Whether the session name/id should be added */ function redirect($url = null, $param = array(), $session = false) { if (!isset($url)) { $url = $_SERVER['PHP_SELF']; } $qs = array(); if ($session) { $qs[] = session_name() .'='. session_id(); } if (is_array($param) && count($param)) { if (count($param)) { foreach ($param as $key => $val) { if (is_string($key)) { $qs[] = urlencode($key) .'='. urlencode($val); } else { $qs[] = urlencode($val) .'='. urlencode(@$GLOBALS[$val]); } } } } if ($qstr = implode('&', $qs)) { $purl = parse_url($url); $url .= (isset($purl['query']) ? '&' : '?') . $qstr; } parent::redirect($url); } /**#@+ * @author Davey Shafik <davey@php.net> * @param int $http_code HTTP Code to check * @access public */ /** * Return HTTP Status Code Type * * @return int|false */ function getStatusType($http_code) { if(is_int($http_code) && defined('HTTP_HEADER_STATUS_' .$http_code) || defined($http_code)) { $type = substr($http_code,0,1); switch ($type) { case HTTP_HEADER_STATUS_INFORMATIONAL: case HTTP_HEADER_STATUS_SUCCESSFUL: case HTTP_HEADER_STATUS_REDIRECT: case HTTP_HEADER_STATUS_CLIENT_ERROR: case HTTP_HEADER_STATUS_SERVER_ERROR: return $type; break; default: return false; break; } } else { return false; } } /** * Return Status Code Message * * @return string|false */ function getStatusText($http_code) { if ($this->getStatusType($http_code)) { if (is_int($http_code) && defined('HTTP_HEADER_STATUS_' .$http_code)) { return substr(constant('HTTP_HEADER_STATUS_' .$http_code),4); } else { return substr($http_code,4); } } else { return false; } } /** * Checks if HTTP Status code is Information (1xx) * * @return boolean */ function isInformational($http_code) { if ($status_type = $this->getStatusType($http_code)) { return $status_type{0} == HTTP_HEADER_STATUS_INFORMATIONAL; } else { return false; } } /** * Checks if HTTP Status code is Successful (2xx) * * @return boolean */ function isSuccessful($http_code) { if ($status_type = $this->getStatusType($http_code)) { return $status_type{0} == HTTP_HEADER_STATUS_SUCCESSFUL; } else { return false; } } /** * Checks if HTTP Status code is a Redirect (3xx) * * @return boolean */ function isRedirect($http_code) { if ($status_type = $this->getStatusType($http_code)) { return $status_type{0} == HTTP_HEADER_STATUS_REDIRECT; } else { return false; } } /** * Checks if HTTP Status code is a Client Error (4xx) * * @return boolean */ function isClientError($http_code) { if ($status_type = $this->getStatusType($http_code)) { return $status_type{0} == HTTP_HEADER_STATUS_CLIENT_ERROR; } else { return false; } } /** * Checks if HTTP Status code is Server Error (5xx) * * @return boolean */ function isServerError($http_code) { if ($status_type = $this->getStatusType($http_code)) { return $status_type{0} == HTTP_HEADER_STATUS_SERVER_ERROR; } else { return false; } } /** * Checks if HTTP Status code is Server OR Client Error (4xx or 5xx) * * @return boolean */ function isError($http_code) { if ($status_type = $this->getStatusType($http_code)) { return (($status_type == HTTP_HEADER_STATUS_CLIENT_ERROR) || ($status_type == HTTP_HEADER_STATUS_SERVER_ERROR)) ? true : false; } else { return false; } } /**#@-*/}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?