Page 1 of 1

getting the headers from a HTTP POST request

Posted: Sun Dec 27, 2009 11:49 pm
by dhruvg
hey.

i have a php script which processes special http post requests. all these post requests have an additional key-value pair in their header wherein the key is called 'Authorization'.

so i have a php script which is getting these types of post requests and i know how to get the body data of the post request using $_POST['key'].

but i want to also get the value of the header key, 'Authorization'. i am unsure how to get the value of this header. can I use $_SERVER['Authorization']?

thanks in advance.

Re: getting the headers from a HTTP POST request

Posted: Mon Dec 28, 2009 12:03 am
by requinix
Take a look at this.

Re: getting the headers from a HTTP POST request

Posted: Mon Dec 28, 2009 12:35 am
by manohoo
Try this, you might find it useful:

Code: Select all

 
foreach($_POST as $key=>$value) 
  { 
    $$key = $value;
    echo $$key.": ".$value."<br />";
  }
 

Re: getting the headers from a HTTP POST request

Posted: Mon Dec 28, 2009 12:36 pm
by Darhazer
If PHP is installed as apache module: apache_request_headers();

I think PHP also populates custom headers in $_SERVER with X_ prefix, but I'm not sure what are the conditions to do this anyway, so I'm never relying on this.