Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access the raw HTTP request data with PHP/apache?

Tags:

php

apache

I was wondering if there was a way to get at the raw HTTP request data in PHP running on apache that doesn't involve using any additional extensions. I've seen the HTTP functions in the manual, but I don't have the option of installing an extension in my environment.

While I can access the information from $_SERVER, I would like to see the raw request exactly as it was sent to the server. PHP munges the header names to suit its own array key style, for eg. Some-Test-Header becomes HTTP_X_SOME_TEST_HEADER. This is not what I need.

like image 246
Shabbyrobe Avatar asked Oct 03 '08 03:10

Shabbyrobe


People also ask

What is a raw HTTP request?

The Raw HTTP action sends a HTTP request to a web server. How the response is treated depends on the method, but in general the status code and the response headers are returned in variables defined as part of the page load options.


2 Answers

Use the following php wrapper:

$raw_post = file_get_contents("php://input"); 
like image 143
Bretticus Avatar answered Sep 30 '22 20:09

Bretticus


Do you mean the information contained in $_SERVER?

print_r($_SERVER);

Edit:

Would this do then?

foreach(getallheaders() as $key=>$value)  {
    print $key.': '.$value."<br />";
}
like image 43
Owen Avatar answered Sep 30 '22 20:09

Owen