note 72498 modified in function.apache-request-headers by danbrown

From: Date: Mon, 08 Jun 2009 18:49:13 +0000
Subject: note 72498 modified in function.apache-request-headers by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156483@lists.php.net to get a copy of this message
The following code will implement an approximation of apache_request_headers for lighttpd making most scripts that use the function portable between the two platforms. Caveats are: 1. This function will convert any _ in a header key to a - 2. This function will capitalize the first character and first character after each hyphen in each header key and lower case the rest of the key. This does not cause a problem with standard headers which are capitalized in this manner but may cause custom headers to appear in a different case to apache. <?php if (!function_exists('apache_request_headers')) { eval(' 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; } } return $out; } '); } ?> --was-- The following code will implement an approximation of apache_request_headers for lighttpd making most scripts that use the function portable between the two platforms. Caveats are: 1. This function will convert any _ in a header key to a - 2. This function will capitalize the first character and first character after each hyphen in each header key and lower case the rest of the key. This does not cause a problem with standard headers which are capitalized in this manner but may cause custom headers to appear in a different case to apache. if (!function_exists('apache_request_headers')) { eval(' 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; } } return $out; } '); } http://php.net/manual/en/function.apache-request-headers.php

« previous php.notes (#156483) next »