色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

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

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
)

php技術PHP獲取http請求的頭信息實現步驟,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 鄂尔多斯市| 南溪县| 浪卡子县| 义乌市| 岳池县| 凤阳县| 嘉荫县| 芮城县| 鄂温| 花垣县| 鹤壁市| 清镇市| 贵港市| 雅安市| 阜新市| 英吉沙县| 油尖旺区| 广德县| 成武县| 建水县| 上饶县| 辉南县| 久治县| 阳东县| 镇康县| 旬邑县| 新郑市| 金阳县| 丰镇市| 安西县| 同德县| 洞头县| 绥德县| 和政县| 青冈县| 商都县| 辉南县| 巨鹿县| 若羌县| 新营市| 独山县|