从 PHP 中的当前请求中获取 http 标头 [英] Get the http headers from current request in PHP

查看:24
本文介绍了从 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() 但我收到 Call to undefined function 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 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆