简体   繁体   English

是否有apache_request_headers用于显示HTTP标头

[英]Is there a apache_request_headers alternatve for displaying HTTP Headers

I'm currently developing an app in a IGB (In-Game-Browser) for an Online MMO. 我正在开发一个用于在线MMO的IGB(游戏内浏览器)应用程序。 For third party development the browser sends HTTP headers with in game information such as Locations, Item ID's, Items Type ID's, etc,. 对于第三方开发,浏览器会在游戏信息中发送HTTP标头,例如位置,项目ID,项目类型ID等。

It's a small script I've been using to practice with. 这是我一直用来练习的小脚本。 This script works on my local server and like everyone else who's posted on this issue it does not work on my web server. 此脚本适用于我的本地服务器,就像在此问题上发布的其他人一样,它在我的Web服务器上不起作用。 I have come to the conclusion that this is due to Apache not being installed as a module. 我得出结论,这是由于Apache没有作为模块安装。 I spoke with my hosting provider. 我与我的托管服务提供商交谈过 They said they could not tell me anything other than I need to find an alternative to "apache_request_headers". 他们说他们不能告诉我除了我需要找到“apache_request_headers”的替代品之外的任何东西。 I've looked over all the previously posted issues on this topic on this site and I'm unable to see how it all fits together. 我已经查看了此网站上此主题的所有先前发布的问题,我无法看到它们是如何组合在一起的。 How to use the examples on here to accomplish my end result. 如何使用这里的示例来完成我的最终结果。 Like this [question]: Call to undefined function apache_request_headers() 像这样[问题]: 调用未定义的函数apache_request_headers()

My code: 我的代码:

<?php
$headers = apache_request_headers();

foreach ($headers as $header => $value) {
    echo "$header: $value <br />\n";
}
?>

My error: 我的错误:

Fatal error: Call to undefined function apache_request_headers() in /home/ncgotggb/public_html/ezalternatives.com/index.php on line 2

I have been learning as I go this year and it's been self taught and at a fast pace so I'm still newbish to alot of these concepts. 我今年一直在学习,而且这是自学和快节奏的,所以我对这些概念还很新意。 At this point tho I have no choice I'm heavily committed and need to complete it. 在这一点上,我别无选择,我已经承诺并需要完成它。 When displaying your answer It would be greatly appreciated if you showed your solution in complete form. 显示您的答案如果您以完整的形式展示您的解决方案,将不胜感激。

It sounds like your local server is running Apache and your remote server is not, as this function only works with Apache (unless the server is running PHP 5.4.0, then it also works under FastCGI. 听起来你的本地服务器正在运行Apache而你的远程服务器不是,因为这个函数只适用于Apache(除非服务器运行的是PHP 5.4.0,否则它也适用于FastCGI。

On the PHP Manual page for this function, one of the commenters included a replacement function that will be declared only if the built-in one doesn't exist. 在此函数的PHP Manual页面上,其中一个评论者包含一个替换函数,只有在内置函数不存在时才会声明该函数。 I haven't tested this, but I've seen the same function posted elsewhere. 我没有测试过这个,但我看到其他地方发布的功能相同。

if( !function_exists('apache_request_headers') ) {
    function apache_request_headers() {
        $arh = array();
        $rx_http = '/\AHTTP_/';

        foreach($_SERVER as $key => $val) {
            if( preg_match($rx_http, $key) ) {
                $arh_key = preg_replace($rx_http, '', $key);
                $rx_matches = array();
           // do some nasty string manipulations to restore the original letter case
           // this should work in most cases
                $rx_matches = explode('_', $arh_key);

                if( count($rx_matches) > 0 and strlen($arh_key) > 2 ) {
                    foreach($rx_matches as $ak_key => $ak_val) {
                        $rx_matches[$ak_key] = ucfirst($ak_val);
                    }

                    $arh_key = implode('-', $rx_matches);
                }

                $arh[$arh_key] = $val;
            }
        }

        return( $arh );
    }
}

我发现我在ISP Config中的网站设置为PHP为'Fast-CGI' - 将其更改为'MOD-PHP'很好地解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM