国产探花免费观看_亚洲丰满少妇自慰呻吟_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
)
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 饶阳县| 新郑市| 怀仁县| 台南县| 建平县| 马边| 榆社县| 四会市| 洪洞县| 民乐县| 桃园县| 周宁县| 庆元县| 井研县| 平武县| 搜索| 定兴县| 自治县| 大渡口区| 历史| 德钦县| 饶平县| 榆树市| 龙南县| 城口县| 大姚县| 保德县| 宝丰县| 保靖县| 比如县| 云龙县| 光山县| 兴业县| 永顺县| 林口县| 肃北| 靖江市| 玛沁县| 安阳市| 平江县| 武威市|