<?php
// Replace XXXXXX_XXXX with the name of the header you need in UPPERCASE (and with '-' replaced by '_')
$headerStringValue = $_SERVER['HTTP_XXXXXX_XXXX'];
< p > < br >
ELSE IF:你将PHP作为Apache模块运行,或者在php5.4中,使用FastCGI(简单方法):
<?php
/**
* @param $pHeaderKey
* @return mixed
*/
function get_header( $pHeaderKey )
{
// Expanded for clarity.
$headerKey = str_replace('-', '_', $pHeaderKey);
$headerKey = strtoupper($headerKey);
$headerValue = NULL;
// Uncomment the if when you do not want to throw an undefined index error.
// I leave it out because I like my app to tell me when it can't find something I expect.
//if ( array_key_exists($headerKey, $_SERVER) ) {
$headerValue = $_SERVER[ $headerKey ];
//}
return $headerValue;
}
// X-Requested-With mainly used to identify Ajax requests. Most JavaScript frameworks
// send this header with value of XMLHttpRequest, so this will not always be present.
$header_x_requested_with = get_header( 'X-Requested-With' );
/**
* @var string $headerName case insensitive header name
*
* @return string|null header value or null if not found
*/
function get_header($headerName)
{
$headers = getallheaders();
return isset($headerName) ? $headers[$headerName] : null;
}