1

I´m sending an ajax request with a custom header called Authorization, and I'm trying to get that header with PHP

if (!function_exists('getallheaders')) 
    { 
        function getallheaders() 
        { 
               $headers = array();
                foreach ($_SERVER as $k => $v)
                {
                if (substr($k, 0, 5) == "HTTP_")
                {
                $k = str_replace('_', ' ', substr($k, 5));
                $k = str_replace(' ', '-', ucwords(strtolower($k)));
                $headers[$k] = $v;
                }
                }
                return $headers;

        } 
    }
    $val = getallheaders();
    echo $val;

and I get all the headers but not the custom one

val: Object{
  Accept: "application/json, text/plain, */*"
  Accept-Encoding: "gzip, deflate, sdch"
  Accept-Language: "es-ES,es;q=0.8,en;q=0.6"
  Connection: "keep-alive"
  Host: "www.localhost.com"
  Origin: "http://localhost"
  Referer: "http://localhost/gestion/"
  User-Agent: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML,           like Gecko) Chrome/41.0.2272.101 Safari/537.36"
}

enter image description here

Any clues why I'm not getting header Authorization?

Diego Vega
  • 223
  • 6
  • 16
  • This question was probably answered here: [http://stackoverflow.com/questions/17488656/zend-server-windows-authorization-header-is-not-passed-to-php-script](http://stackoverflow.com/questions/17488656/zend-server-windows-authorization-header-is-not-passed-to-php-script) In this answer, there is a workaround described. Does it help you? – peter_the_oak Apr 02 '15 at 11:57

1 Answers1

0

For custom headers the $_SERVER global in php documentation state that

There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here. That said, a large number of these variables are accounted for in the » CGI/1.1 specification, so you should be able to expect those

so try to use apache_request_headers which may help you if your working with apache as a server

Server Quote

apache_request_headers

AboElzooz
  • 309
  • 4
  • 16