/* 获取HTTP 信息请求头 */

nginx 服务器环境

$HTTP_Header = getHeader();

/* 获取HTTP 信息请求头 */
function getHeader() {
    $headers = array(); 
    foreach ($_SERVER as $key => $value) {
        if ('HTTP_' == substr($key, 0, 5)) { 
            $headers[str_replace('_', '-', substr($key, 5))] = $value; 
        }
        if (isset($_SERVER['PHP_AUTH_DIGEST'])) { 
            $header['AUTHORIZATION'] = $_SERVER['PHP_AUTH_DIGEST']; 
        } elseif (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { 
            $header['AUTHORIZATION'] = base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']); 
        } 
        if (isset($_SERVER['CONTENT_LENGTH'])) { 
            $header['CONTENT-LENGTH'] = $_SERVER['CONTENT_LENGTH']; 
        } 
        if (isset($_SERVER['CONTENT_TYPE'])) { 
            $header['CONTENT-TYPE'] = $_SERVER['CONTENT_TYPE']; 
        }
    }
    return $headers;
}

你可能感兴趣的:(PHP,获取http请求头header)