Php 调用未定义的函数apache_request_
我之所以发布这个帖子,是因为其他帖子都没有帮我解决问题。我正在chrome上使用slim和高级RESTAPI应用程序进行测试。我在网上尝试了很多建议,但都不管用。我正在hostgator上运行PHP5.5。我在传递授权标头时遇到错误: 调用未定义的函数apache_request_headers()Php 调用未定义的函数apache_request_,php,apache,http,slim,Php,Apache,Http,Slim,我之所以发布这个帖子,是因为其他帖子都没有帮我解决问题。我正在chrome上使用slim和高级RESTAPI应用程序进行测试。我在网上尝试了很多建议,但都不管用。我正在hostgator上运行PHP5.5。我在传递授权标头时遇到错误: 调用未定义的函数apache_request_headers() PHP5.4.0及更高版本支持apache_请求_头()。但还有其他解决方案,如下面的代码,它来自: PHP5.4.0及更高版本支持apache_请求_头()。但还有其他解决方案,如下面的代码,它来
PHP5.4.0及更高版本支持apache_请求_头()。但还有其他解决方案,如下面的代码,它来自:
PHP5.4.0及更高版本支持apache_请求_头()。但还有其他解决方案,如下面的代码,它来自:
更新,这似乎解决了标题问题
if (!function_exists('apache_request_headers')) {
function apache_request_headers() {
foreach($_SERVER as $key=>$value) {
if (substr($key,0,5)=="HTTP_") {
$key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5)))));
$out[$key]=$value;
}else{
$out[$key]=$value;
}
}
return $out;
}
}
更新,这似乎解决了标题问题
if (!function_exists('apache_request_headers')) {
function apache_request_headers() {
foreach($_SERVER as $key=>$value) {
if (substr($key,0,5)=="HTTP_") {
$key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5)))));
$out[$key]=$value;
}else{
$out[$key]=$value;
}
}
return $out;
}
}
函数apache-request-headers(),如果仅适用于apache。Hostgrator很可能使用了其他东西,如Nginx。如果仅适用于apache,我在本地机器函数apache-request-headers()上也会遇到同样的错误。Hostgrator很可能使用了其他东西,比如Nginx。我在本地机器上遇到了相同的错误
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 );
}
if (!function_exists('apache_request_headers')) {
function apache_request_headers() {
foreach($_SERVER as $key=>$value) {
if (substr($key,0,5)=="HTTP_") {
$key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5)))));
$out[$key]=$value;
}else{
$out[$key]=$value;
}
}
return $out;
}
}