getting the headers from a HTTP POST request

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dhruvg
Forum Newbie
Posts: 3
Joined: Sun Dec 27, 2009 11:44 pm

getting the headers from a HTTP POST request

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: getting the headers from a HTTP POST request

Post by requinix »

Take a look at this.
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: getting the headers from a HTTP POST request

Post by manohoo »

Try this, you might find it useful:

Code: Select all

 
foreach($_POST as $key=>$value) 
  { 
    $$key = $value;
    echo $$key.": ".$value."<br />";
  }
 
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: getting the headers from a HTTP POST request

Post 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.
Post Reply