php获取http请求头信息
php 获取http请求头,封装成方法getRequestHeaders,直接调用;
直接上代码
/**
* PHP获取http请求头
* @return array 返回数组
*/
function getRequestHeaders() {
$headers = array();
foreach ($_SERVER as $key => $value) {
if ('HTTP_' == substr($key, 0, 5)) {
$key=substr($key, 5);
$key = strtolower($key);
$key = str_replace('_', ' ', $key);
$key = ucwords($key);
$key = str_replace(' ','-',$key);
$headers[$key] = $value;
}
}
return $headers;
}
执行结果:
Array ( [Cookie] => GoodsOrderSaleCookie_GoodsWarehouseID=null; GoodsOrderSaleCookie_GoodsOrderModel=1; PHPSESSID=r1rb3a9ektosjegm9fdpesb6f6 [Accept-Language] => zh-CN,zh;q=0.9 [Accept-Encoding] => gzip, deflate [Accept] => text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 [User-Agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.80 Safari/537.36 [Upgrade-Insecure-Requests] => 1 [Cache-Control] => no-cache [Pragma] => no-cache [Connection] => keep-alive [Host] => www.prison.me )
请先登录后再评论登录