Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Apache-specific Functions : getallheaders

getallheaders

Fetch all HTTP request headers (PHP 4, PHP 5)
array getallheaders ( )

Fetches all HTTP requests from the current request.

This function is an alias for apache_request_headers(). Please read the apache_request_headers() documentation for more information on how this function works.

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

Return Values

An associative array of all the HTTP headers in the current request, or FALSE on failure.

ChangeLog

Version Description
4.3.0 Became an alias for apache_request_headers(). Essentially, it was renamed. This is because this function only works with Apache.

Notes

Note:

As of PHP 4.3.3 you can use this function with the NSAPI server module in Netscape/iPlanet/SunONE webservers, too.

Code Examples / Notes » getallheaders

jukkaho

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.


tigr

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


zevs

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"


lorro

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.

tigr

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


jarl

All the environment variables can be found here:
http://www.php.net/manual/language.variables.predefined.php


Change Language


Follow Navioo On Twitter
apache_child_terminate
apache_get_modules
apache_get_version
apache_getenv
apache_lookup_uri
apache_note
apache_request_headers
apache_reset_timeout
apache_response_headers
apache_setenv
ascii2ebcdic
ebcdic2ascii
getallheaders
virtual
eXTReMe Tracker