note 99395 deleted from reserved.variables.server by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 19:06:54 +0000 |
| Subject: | note 99395 deleted from reserved.variables.server by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217889@lists.php.net to get a copy of this message | ||
Note Submitter: dtomasiewicz at gmail dot com
----
To get an associative array of HTTP request headers formatted similarly to get_headers(), this will
do the trick:
<?php
/**
* Transforms $_SERVER HTTP headers into a nice associative array. For example:
* array(
* 'Referer' => 'example.com',
* 'X-Requested-With' => 'XMLHttpRequest'
* )
*/
function get_request_headers() {
$headers = array();
foreach($_SERVER as $key => $value) {
if(strpos($key, 'HTTP_') === 0) {
$headers[str_replace(' ', '-', ucwords(str_replace('_', '
', strtolower(substr($key, 5)))))] = $value;
}
}
return $headers;
}
?>