And even better one, that absolutely mimics getallheaders behaviour (including keynames - first character in each word is uppercase and words separated with '-' instead of underscore), and still does not use regexp:
<?php
function emu_getallheaders() {
foreach($_SERVER as $name => $value)
if(substr($name, 0, 5) == 'HTTP_')
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
return $headers;
}
?>
getallheaders
(PHP 4, PHP 5)
getallheaders — Recuperar todas las cabeceras de petición HTTP
Descripción
array getallheaders
( void
)
Recupera todas las cabeceras HTTP de la petición actual.
Esta función es un alias de apache_request_headers(). Por favor lea la documentación de apache_request_headers() para más información sobre cómo trabaja esta función.
This function is only supported when PHP is installed as an Apache module.
Valores retornados
Una matriz asociativa de todas las cabeceras HTTP en la petición actual, o FALSE en caso de fallo.
Registro de cambios
| Versión | Descripción |
|---|---|
| 4.3.0 | Se convierte en un alias de apache_request_headers(). Básicamente, fue renombrada. Esto se debe a que esta función solo trabaja con Apache. |
Notes
Note: A partir de PHP 4.3.3 se puede usar tambien esta funcion con el modulo de servidor NSAPI de los servidores web, Netscape/iPlanet/SunONE.
getallheaders
tigr at mail15 dot com
19-May-2006 02:08
19-May-2006 02:08
tigr at mail15 dot com
19-May-2006 01:44
19-May-2006 01:44
Just a bit faster version of ZevS' function (does not use regular expressions and does not require POSIX regexps that is in PECL in php6):
<?php
function emu_getallheaders() {
foreach($_SERVER as $name => $value)
if(substr($name, 0, 5) == 'HTTP_')
$headers[substr($name, 5)] = $value;
return $headers;
}
?>
lorro at lorro dot hu
19-Apr-2005 04:25
19-Apr-2005 04:25
Beware that RFC2616 (HTTP/1.1) defines header fields as case-insensitive entities. Therefore, array keys of getallheaders() should be converted first to lower- or uppercase and processed such.
ZevS
17-Apr-2005 11:24
17-Apr-2005 11:24
if PHP installed not as Apache-module:
<?php
function emu_getallheaders() {
foreach($_SERVER as $h=>$v)
if(ereg('HTTP_(.+)',$h,$hp))
$headers[$hp[1]]=$v;
return $headers;
}
?>
I put this code to file "/var/www/include", and edit php.ini:
auto_prepend_file = "/var/www/include"
jukkaho at mail dot student dot oulu dot fi
17-Jan-2003 12:14
17-Jan-2003 12:14
This function really is useful. Although $_SERVER['HTTP_*']-variables seem to include all request headers, they are really only the most generally needed - not all of them.
One example that needs this functionality is Digest Authentication (http://www.ietf.org/rfc/rfc2617.txt). When implementing it in PHP script, you can't read client's "Authorization"-header without this function.
jarl at diku dot dk
25-Mar-2000 01:15
25-Mar-2000 01:15
All the environment variables can be found here:
http://www.php.net/manual/language.variables.predefined.php
