aph*_*hoe 26
您可以使用getallheaders()
获取发送的所有HTTP标头的数组.
$headers = getallheaders();
foreach($headers as $key=>$val){
echo $key . ': ' . $val . '<br>';
}
Run Code Online (Sandbox Code Playgroud)
Gum*_*mbo 21
每个HTTP请求标头字段都在$_SERVER
(除外Cookie
),密钥以HTTP_
.开头.如果你正在使用Apache,你也可以试试apache_request_headers
.
您可以简单地使用apache_request_headers()
或使用别名getallheaders()
.
用法: echo json_encode(getallheaders());
如果上面的函数不存在(旧的PHP或nginx),你可以使用它作为后备:
<?php
if (!function_exists('getallheaders')){
function getallheaders() {
$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;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
89044 次 |
最近记录: |