17

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.

3 Answers 3

13

Use the following php wrapper:

$raw_post = file_get_contents("php://input"); 
Sign up to request clarification or add additional context in comments.

1 Comment

I don't think that gets the http headers though.
10

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 />";
}

1 Comment

Yes, but i want the raw request before it gets parsed into $_SERVER by PHP
3

Try this:

  $request = $_SERVER['SERVER_PROTOCOL'] .' '. $_SERVER['REQUEST_METHOD'] .' '. $_SERVER['REQUEST_URI'] . "\r\n";
  
  foreach (getallheaders() as $key => $value) {
    $request .= trim($key) .': '. trim($value) . "\r\n";
  }
  
  $request .= "\r\n" . file_get_contents('php://input');
  
  echo $request;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.