【问题标题】:Why this php apache_request_headers doesn't work on IIS 7为什么这个 php apache_request_headers 在 IIS 7 上不起作用
【发布时间】:2011-06-15 14:30:14
【问题描述】:

这适用于 Apache,为什么它似乎不适用于 IIS 7?

if(!function_exists('apache_request_headers')) {
    function apache_request_headers() {
        $headers = array();
        foreach($_SERVER as $key => $value) {
            if(substr($key, 0, 5) == 'HTTP_') {
                $headers[str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))))] = $value;
            }
        }
        return $headers;
    }
}

function getCurrentPageUrl() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}    

$a =  apache_request_headers();

$pos = strrpos($a["User-Agent"], "REBOL");

【问题讨论】:

  • 您能否将echo "<pre>", htmlspecialchars(print_r($_SERVER, true)), "</pre>" 的输出添加到您的问题中?
  • 请注意:这不会捕获所有标头字段,例如“Content-Type”或“Content-Length”,因为它们在 $_SERVER 中没有以“HTTP_”为前缀。

标签: php apache iis


【解决方案1】:

查看文档,这是特定于 Apache 的。

http://php.net/manual/en/function.apache-request-headers.php

【讨论】:

  • 他提供了当函数不可用时的回退机制,查看代码。
  • 没错,我看错了。不过有点不清楚,问为什么一个apache特定的方法在IIS下不起作用,即使你已经创建了它,如果它不存在。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-20
  • 2018-06-26
  • 2010-10-29
  • 1970-01-01
相关资源
最近更新 更多