tags:

views:

77

answers:

4

Hi,

I'm creating a framework in PHP, and I need to get the complete raw request done by the browser. So I want something like this in a variable:

POST /lolzorz/xD HTTP/1.1\r\n
Host: localhost\r\n
User-Agent: UserAgentHere/1.0.00\r\n
Content-Type: application/xml; charset=utf-8\r\n
Content-Length: 0\r\n
\r\n
<?xml version="1.0" encoding="UTF-8"?>\r\n
<request>\r\n
<question1 param="value" />\r\n
<question2 param="value" />\r\n
<question3 param="value" />\r\n
</request>\r\n

Is this possible?

My server information:

  • Mac OS X Snow Leopard (10.6.2)
  • Apache2
  • PHP 5 running as a module

Thanks,

A: 

If you mean the server headers from another web page, then use the get_headers() function.

If you mean the headers from the user request of the page, you can use the apache_request_headers() function. Though as kon says, the preferred method is doing this:

<?php $postdata = file_get_contents("php://input"); ?>

You need to make sure you have the always_populate_raw_post_data option on in your php.ini.

DisgruntledGoat
i have read it's preferrable to use file_get_contents("php://input"); to get the raw request data.
kon
A: 

i suppose you have to manually put this together using the $_SERVER vars and the contents of

print_r(getallheaders());
kon
A: 

You can get the request headers with apache_request_headers

Htbaa
+2  A: 

I don't think php can get hold of the headers part of the raw input stream. (getallheaders()/apache _request_headers() has already been mentioned).
But at least you can read the raw post data via the php://input stream.

VolkerK
I'll use getallheaders and input stream, thanks!
Time Machine