tags:

views:

64

answers:

6

I need some PHP code that does a dump of all the information in an HTTP request, including headers and the contents of any information included in a POST request. Basically, a diagnostic tool that spits out exactly what I send to a server.

Does anyone have some code that does this?

+2  A: 

A simple way would be:

<?php
print_r($_SERVER);
print_r($_POST);
print_r($_GET);
print_r($_FILES);
?>

A bit of massaging would be required to get everything in the order you want, and to exclude the variables you are not interested in, but should give you a start.

Vinko Vrsalovic
+1  A: 

Well, you can read the entirety of the POST body like so

echo file_get_contents( 'php://input' );

And, assuming your webserver is Apache, you can read the request headers like so

$requestHeaders = apache_request_headers();
Peter Bailey
+1  A: 

in addition, you can use get_headers(). it doesn't depend on apache..

print_r(get_headers());
kgb
+2  A: 

Lastly:

print_r($_REQUEST);

That covers most incoming items: PHP.net Manual: $_REQUEST

Marco Ceppi
+1  A: 

If you want actual HTTP Headers (both request and response), give hurl.it a try.

You can use the PHP command apache_request_headers() to get the request headers and apache_response_headers() to get the current response headers. Note that response can be changed later in the PHP script as long as content has not been served.

sirlancelot
A: 

This doesn't directly answer your question, but assuming your use case is similar to mine (diagnostics/debugging/etc) I find the Firefox extension Live HTTP Headers to be an excellent resource. And no need to pull anything together in PHP.

dimo414