本文整理汇总了PHP中http_get_request_headers函数的典型用法代码示例。如果您正苦于以下问题:PHP http_get_request_headers函数的具体用法?PHP http_get_request_headers怎么用?PHP http_get_request_headers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了http_get_request_headers函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: request_headers
/**
* Parses the the HTTP request headers and returns an array containing
* key value pairs. This method is slow, but provides an accurate
* representation of the HTTP request.
*
* // Get http headers into the request
* $request->headers = HTTP::request_headers();
*
* @return HTTP_Header
*/
public static function request_headers()
{
// If running on apache server
if (function_exists('apache_request_headers')) {
// Return the much faster method
return new HTTP_Header(apache_request_headers());
} elseif (extension_loaded('http')) {
// Return the much faster method
return new HTTP_Header(http_get_request_headers());
}
// Setup the output
$headers = array();
// Parse the content type
if (!empty($_SERVER['CONTENT_TYPE'])) {
$headers['content-type'] = $_SERVER['CONTENT_TYPE'];
}
// Parse the content length
if (!empty($_SERVER['CONTENT_LENGTH'])) {
$headers['content-length'] = $_SERVER['CONTENT_LENGTH'];
}
foreach ($_SERVER as $key => $value) {
// If there is no HTTP header here, skip
if (strpos($key, 'HTTP_') !== 0) {
continue;
}
// This is a dirty hack to ensure HTTP_X_FOO_BAR becomes x-foo-bar
$headers[str_replace(array('HTTP_', '_'), array('', '-'), $key)] = $value;
}
return new HTTP_Header($headers);
}
示例2: test_functions
/**
* Test Http functions.
*/
function test_functions()
{
http_cache_last_modified();
http_chunked_decode();
http_deflate();
http_inflate();
http_build_cookie();
http_date();
http_get_request_body_stream();
http_get_request_body();
http_get_request_headers();
http_match_etag();
http_match_modified();
http_match_request_header();
http_support();
http_negotiate_charset();
http_negotiate_content_type();
http_negotiate_language();
ob_deflatehandler();
ob_etaghandler();
ob_inflatehandler();
http_parse_cookie();
http_parse_headers();
http_parse_message();
http_parse_params();
http_persistent_handles_clean();
http_persistent_handles_count();
http_persistent_handles_ident();
http_get();
http_head();
http_post_data();
http_post_fields();
http_put_data();
http_put_file();
http_put_stream();
http_request_body_encode();
http_request_method_exists();
http_request_method_name();
http_request_method_register();
http_request_method_unregister();
http_request();
http_redirect();
http_send_content_disposition();
http_send_content_type();
http_send_data();
http_send_file();
http_send_last_modified();
http_send_status();
http_send_stream();
http_throttle();
http_build_str();
http_build_url();
}
示例3: save
public function save()
{
if (function_exists('apache_request_headers')) {
$requestHeaders = apache_request_headers();
} elseif (function_exists('http_get_request_headers')) {
$requestHeaders = http_get_request_headers();
} else {
$requestHeaders = array();
}
$responseHeaders = array();
foreach (headers_list() as $header) {
if (($pos = strpos($header, ':')) !== false) {
$name = substr($header, 0, $pos);
$value = trim(substr($header, $pos + 1));
if (isset($responseHeaders[$name])) {
if (!is_array($responseHeaders[$name])) {
$responseHeaders[$name] = array($responseHeaders[$name], $value);
} else {
$responseHeaders[$name][] = $value;
}
} else {
$responseHeaders[$name] = $value;
}
} else {
$responseHeaders[] = $header;
}
}
$route = Yii::app()->getUrlManager()->parseUrl(Yii::app()->getRequest());
$action = null;
$actionParams = array();
if (($ca = @Yii::app()->createController($route)) !== null) {
/* @var CController $controller */
/* @var string $actionID */
list($controller, $actionID) = $ca;
if (!$actionID) {
$actionID = $controller->defaultAction;
}
if (($a = $controller->createAction($actionID)) !== null) {
if ($a instanceof CInlineAction) {
$action = get_class($controller) . '::action' . ucfirst($actionID) . '()';
} else {
$action = get_class($a) . '::run()';
}
}
$actionParams = $controller->actionParams;
}
$flashes = array();
$user = Yii::app()->getComponent('user', false);
if ($user instanceof CWebUser) {
$flashes = $user->getFlashes(false);
}
return array('flashes' => $flashes, 'statusCode' => $this->getStatusCode(), 'requestHeaders' => $requestHeaders, 'responseHeaders' => $responseHeaders, 'route' => $route, 'action' => $action, 'actionParams' => $actionParams, 'SERVER' => empty($_SERVER) ? array() : $_SERVER, 'GET' => empty($_GET) ? array() : $_GET, 'POST' => empty($_POST) ? array() : $_POST, 'COOKIE' => empty($_COOKIE) ? array() : $_COOKIE, 'FILES' => empty($_FILES) ? array() : $_FILES, 'SESSION' => empty($_SESSION) ? array() : $_SESSION);
}
示例4: getHeaders
/**
* 返回header头信息
*/
public function getHeaders()
{
if (function_exists('getallheaders')) {
$headers = getallheaders();
} elseif (function_exists('http_get_request_headers')) {
$headers = http_get_request_headers();
} else {
$headers = [];
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
}
return $headers;
}
示例5: parseHeaders
private function parseHeaders()
{
$headers = null;
if (function_exists('http_get_request_headers')) {
//Try to use pcre_http library if it exists
$headers = http_get_request_headers();
} else {
if (function_exists('apache_request_headers')) {
//If not: try to use apache specific headers
$headers = apache_request_headers();
} else {
//If not: not supported - empty headers
$headers = array();
}
}
$this->headers = $headers;
}
示例6: getParams
public static function getParams()
{
$params = array('fileName' => '', 'pathHash' => '', 'name' => '', 'action' => '', 'replica' => 0, 'position' => null, 'configIndex' => 0, 'moveConfigIndex' => 0, 'moveContext' => WebDFS::MOVE_CONTEXT_START, 'getContext' => '', 'propagateDelete' => 1);
// need to create the path info if nothing exists
if (!isset($_SERVER['PATH_INFO']) && isset($_SERVER['REDIRECT_URL'])) {
$_SERVER['PATH_INFO'] = preg_replace('/^.*?\\/([^\\/]+)$/', '\\1', $_SERVER['REDIRECT_URL']);
}
if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] !== '') {
$params['action'] = strtolower($_SERVER['REQUEST_METHOD']);
$params['name'] = trim($_SERVER['PATH_INFO'], '/');
$params['name'] = str_replace(array('\\0'), "", $params['name']);
$params['fileName'] = basename($params['name']);
// hash the path info
$params['pathHash'] = self::getPathHash($params['name']);
$headers = http_get_request_headers();
if (isset($headers[WebDFS::HEADER_REPLICA])) {
$params['replica'] = (int) $headers[WebDFS::HEADER_REPLICA];
}
if (isset($headers[WebDFS::HEADER_POSITION])) {
$params['position'] = (int) $headers[WebDFS::HEADER_POSITION];
}
if (isset($headers[WebDFS::HEADER_CONFIG_INDEX])) {
$params['configIndex'] = (int) $headers[WebDFS::HEADER_CONFIG_INDEX];
}
if (isset($headers[WebDFS::HEADER_MOVE_CONTEXT])) {
$params['moveContext'] = strtolower($headers[WebDFS::HEADER_MOVE_CONTEXT]);
}
if (isset($headers[WebDFS::HEADER_MOVE_CONFIG_INDEX])) {
$params['moveConfigIndex'] = (int) $headers[WebDFS::HEADER_MOVE_CONFIG_INDEX];
}
if (isset($headers[WebDFS::HEADER_GET_CONTEXT])) {
$params['getContext'] = $headers[WebDFS::HEADER_GET_CONTEXT];
}
if (isset($headers[WebDFS::HEADER_CONTENT_LENGTH])) {
$params['contentLength'] = (int) $headers[WebDFS::HEADER_CONTENT_LENGTH];
}
if (isset($headers[WebDFS::HEADER_PROPAGATE_DELETE])) {
$params['propagateDelete'] = (int) $headers[WebDFS::HEADER_PROPAGATE_DELETE];
}
if (isset($headers[WebDFS::HEADER_FORCE_DELETE])) {
$params['forceDelete'] = (int) $headers[WebDFS::HEADER_FORCE_DELETE];
}
}
return $params;
}
示例7: readHeaders
protected function readHeaders()
{
if (function_exists('apache_request_headers')) {
// @codeCoverageIgnoreStart
$headers = apache_request_headers();
} elseif (function_exists('http_get_request_headers')) {
$headers = http_get_request_headers();
} else {
// @codeCoverageIgnoreEnd
$headers = array();
foreach ($this->server() as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
// HTTP_FOO_BAR becomes FOO-BAR
$name = str_replace(array('HTTP_', '_'), array('', '-'), $name);
$headers[$name] = $value;
}
}
}
return $this->normalizeHeaders($headers);
}
示例8: getHeaders
/**
* Returns the header collection.
* The header collection contains incoming HTTP headers.
* @return HeaderCollection the header collection
*/
public function getHeaders()
{
if ($this->_headers === null) {
$this->_headers = new HeaderCollection();
if (function_exists('getallheaders')) {
$headers = getallheaders();
} elseif (function_exists('http_get_request_headers')) {
$headers = http_get_request_headers();
} else {
foreach ($_SERVER as $name => $value) {
if (strncmp($name, 'HTTP_', 5) === 0) {
$name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
$this->_headers->add($name, $value);
}
}
return $this->_headers;
}
foreach ($headers as $name => $value) {
$this->_headers->add($name, $value);
}
}
return $this->_headers;
}
示例9: request_headers
public static function request_headers()
{
if (function_exists("apache_request_headers")) {
return new HTTP_Header(apache_request_headers());
} elseif (extension_loaded("http")) {
$headers = version_compare(phpversion("http"), "2.0.0", ">=") ? \http\Env::getRequestHeader() : http_get_request_headers();
return new HTTP_Header($headers);
}
$headers = array();
if (!empty($_SERVER["CONTENT_TYPE"])) {
$headers["content-type"] = $_SERVER["CONTENT_TYPE"];
}
if (!empty($_SERVER["CONTENT_LENGTH"])) {
$headers["content-length"] = $_SERVER["CONTENT_LENGTH"];
}
foreach ($_SERVER as $key => $value) {
if (strpos($key, "HTTP_") !== 0) {
continue;
}
$headers[str_replace("_", "-", substr($key, 5))] = $value;
}
return new HTTP_Header($headers);
}
示例10: getHeaders
/**
* @return array|false|null
*/
public function getHeaders()
{
if ($this->_headers === null) {
if (function_exists('getallheaders')) {
$this->_headers = getallheaders();
} elseif (function_exists('http_get_request_headers')) {
$this->_headers = http_get_request_headers();
} else {
foreach ($_SERVER as $name => $value) {
if ($name = $this->_nameConver($name)) {
$this->_headers[$name] = $value;
}
}
}
}
return $this->_headers;
}
示例11: header
public function header($key = null)
{
$headers = http_get_request_headers();
return is_null($key) ? $headers : $headers[$key];
}
示例12: createFromGlobals
/**
* Build the request using the (super) global variables.
*
* @uses http_get_request_headers()
* @uses http_get_request_body()
*
* @return \Phpf\Request
*/
public static function createFromGlobals()
{
$method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
$query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
// Set request path
if (isset($_SERVER['PATH_INFO'])) {
$uri = urldecode($_SERVER['PATH_INFO']);
} else {
$uri = urldecode($_SERVER['REQUEST_URI']);
// Remove query string from path
if (false !== ($qpos = strpos($uri, '?'))) {
$uri = substr($uri, 0, $qpos);
}
}
$headers = http_get_request_headers();
// Set request body data as per RFC 3875 4.2, 4.3
if ('HEAD' === $method || 'POST' === $method && empty($headers['content-length'])) {
// HEAD requests have no body - ha!
// POST requests must have content-length
$data = array();
} else {
if ('POST' === $method && isset($headers['content-type']) && 'multipart/form-data' === $headers['content-type']) {
// Use php://input except for POST with enctype="multipart/form-data"
// @see {@link http://us3.php.net/manual/en/wrappers.php.php}
$data = $_POST;
} else {
parse_str(http_get_request_body(), $data);
}
}
return new static($method, $uri, $query, $headers, $data, $_COOKIE, $_FILES);
}
示例13: http_get_request_headers
<?php
$request_headers = http_get_request_headers();
$dataType = isset($request_headers["X-File-Type"]) ? $request_headers["X-File-Type"] : "image/jpg";
echo "data:" . $dataType . ";base64," . base64_encode(http_get_request_body());
示例14: getRequestHeaders
public function getRequestHeaders()
{
if ($this->_headers === null) {
$this->_headers = [];
if (function_exists('getallheaders')) {
foreach (getallheaders() as $name => $value) {
$this->_headers[$name] = $value;
}
} elseif (function_exists('http_get_request_headers')) {
foreach (http_get_request_headers() as $name => $value) {
$this->_headers[$name] = $value;
}
} else {
foreach ($_SERVER as $name => $value) {
if (strncmp($name, 'HTTP_', 5) === 0) {
$name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
$this->_headers[$name] = $value;
}
}
}
}
return $this->_headers;
}
示例15: getHeaders
public static function getHeaders()
{
$headers = array();
if (function_exists('getallheaders')) {
$headers = getallheaders();
} elseif (function_exists('apache_request_headers')) {
$headers = apache_request_headers();
} elseif (function_exists('http_get_request_headers')) {
$headers = http_get_request_headers();
}
foreach ($headers as $key => $value) {
$key = 'HTTP_' . strtoupper(str_replace('-', '_', $key));
if (!isset($_SERVER[$key])) {
$_SERVER[$key] = $value;
}
}
return $headers;
}