【发布时间】:2020-03-15 00:00:50
【问题描述】:
apache_request_headers函数会在 NGINX 网络上运行吗 服务器。如果不是 NGINX 与之平行的功能是什么
【问题讨论】:
标签: php apache nginx http-headers
apache_request_headers函数会在 NGINX 网络上运行吗 服务器。如果不是 NGINX 与之平行的功能是什么
【问题讨论】:
标签: php apache nginx http-headers
有些人在 PHP 文档网站上编写了自己的函数。
https://www.php.net/manual/en/function.apache-request-headers.php
<?php
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 );
}
}
看看有没有帮助(没试过)。
【讨论】:
foreach 循环。我想要更优化的解决方案
根据文档: https://www.php.net/manual/en/function.apache-request-headers.php
从当前请求中获取所有 HTTP 请求标头。在 Netscape/iPlanet/SunONE 网络服务器中的 Apache、FastCGI、CLI、FPM 和 NSAPI 服务器模块中工作。
如果您在 UNIX 上通过 FPM 套接字运行 PHP,或使用 FastCGI 接口,则此功能将起作用。事实上,以apache 开头的事实是具有误导性的,但几乎不是 PHP 函数命名的典型。
【讨论】: