国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 幫助中心 > 正文

PHP獲取http請求的頭信息實現步驟

2024-07-09 22:40:46
字體:
來源:轉載
供稿:網友
PHP手冊提供了現成的函數:
getallheaders
(PHP 4, PHP 5)
getallheaders ― Fetch all HTTP request headers
說明
array getallheaders ( void )
Fetches all HTTP headers from the current request.
This function is an alias for apache_request_headers(). Please read theapache_request_headers() documentation for more information on how this function works.
返回值
An associative array of all the HTTP headers in the current request, orFALSE on failure.
Example #1 getallheaders() example
復制代碼 代碼如下:
<?php
foreach (getallheaders() as $name => $value) {
echo "$name: $value/n";
}
?>

不過這個函數只能在apache環境下使用,iis或者nginx并不支持,可以通過自定義函數實現
復制代碼 代碼如下:
<?php
<SPAN class=html>if (!function_exists('getallheaders'))
{
    function getallheaders()
    {
       foreach ($_SERVER as $name => $value)
       {
           if (substr($name, 0, 5) == 'HTTP_')
           {
               $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
           }
       }
       return $headers;
    }
}</SPAN>
?>

好了,看看都打印出了啥吧
復制代碼 代碼如下:
<?php
print_r(getallheaders());

獲得結果:
復制代碼 代碼如下:
Array
(
[Accept] => */*
[Accept-Language] => zh-cn
[Accept-Encoding] => gzip, deflate
[User-Agent] => Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)
[Host] => localhost
[Connection] => Keep-Alive
)
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黔江区| 洞口县| 厦门市| 海淀区| 铜梁县| 婺源县| 凤台县| 兰坪| 九江市| 隆林| 鄂托克前旗| 竹山县| 昌平区| 正安县| 康平县| 古丈县| 淮阳县| 和龙市| 南康市| 昌都县| 佳木斯市| 万安县| 孟津县| 佛冈县| 丁青县| 昭觉县| 乌苏市| 本溪| 成安县| 伊金霍洛旗| 铁岭县| 朝阳区| 上林县| 高雄县| 曲阜市| 行唐县| 周口市| 长海县| 黔南| 图木舒克市| 汾阳市|