咨询电话:
15628812133
17
2018/11

PHP接收http请求头信息

发布时间:2018-11-17 12:12:49
发布者:pengyifeng
浏览量:
0

1、PHP 自带函数 getallheaders()

此函数传回现行的请求的所有HTTP标头,传回值是一数组形态,只能在是apache环境下使用

foreach (getallheaders() as $name => $value) {    echo "$name: $value\n";
}

PHP接收http请求头信息

2、自定义函数

function em_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;
}

PHP接收http请求头信息

关键词:
返回列表