本文介绍了从PHP中获取当前请求的http标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用PHP获取当前请求的http标头?我使用Apache作为网络服务器,但是使用nginx。

Is it possible to get the http headers of the current request with PHP? I am not using Apache as the web-server, but using nginx.

我尝试使用 getallheaders()但是我得到调用未定义的函数getallheaders()

I tried using getallheaders() but I am getting Call to undefined function getallheaders().

推荐答案

从某人写的文件中获取评论 ...

Taken from the documentation someone wrote a comment...

if (!function_exists('getallheaders'))
{
    function getallheaders()
    {
       $headers = array ();
       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标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 17:17
查看更多