Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined function apache_request_headers()

Tags:

php

I've just switched my scripts to a different server. On the previous server this worked flawlessly, and now that I've switched them to a different server, I can't understand the problem.

I'm not sure it would help, but here's the relevant code.

$headers = apache_request_headers();

PHP Version is: PHP 5.3.2

like image 342
Rob Avatar asked May 26 '10 19:05

Rob


2 Answers

You can use the following replacement function:

<?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 ); } /// } /// ?> 

Source: PHP Manual

like image 162
Babatunde Adeyemi Avatar answered Sep 21 '22 01:09

Babatunde Adeyemi


From the docs, before the release of PHP 5.4.0:

This function is only supported when PHP is installed as an Apache module.

PHP 5.4.0 and later support this function unconditionally.

Said docs also include replacement functions that mimic the functionality of apache_request_headers by stepping through $_SERVER.

like image 39
ceejayoz Avatar answered Sep 21 '22 01:09

ceejayoz