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

首頁 > 開發 > PHP > 正文

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

2024-05-04 23:13:00
字體:
來源:轉載
供稿:網友
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
)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 中宁县| 东乡县| 盐津县| 辽源市| 苏尼特左旗| 呼伦贝尔市| 漾濞| 花垣县| 普兰店市| 女性| 合作市| 西盟| 布尔津县| 乡宁县| 瓦房店市| 桐城市| 冕宁县| 崇仁县| 威信县| 克东县| 瓮安县| 当阳市| 清水县| 汶上县| 华亭县| 平阳县| 海丰县| 乌拉特中旗| 淮滨县| 抚远县| 武强县| 泸西县| 潮州市| 兰西县| 榆林市| 上高县| 桓台县| 四会市| 夏河县| 夏河县| 乐亭县|