How to print all information from an HTTP request to the screen, in PHP
In PHP, you can use the $_SERVER
superglobal array to access information about the current HTTP request. To print all of the information from the request, you can use a combination of the print_r()
function and the $_SERVER
array. Here's an example:
This will print all of the available information from the request, including the request method (e.g. GET, POST), headers, server information, and more.
You can also access specific information from the request by using the array keys. For example, to print the request method, you can use:
echo $_SERVER['REQUEST_METHOD'];
To print the headers you could use:
<?php
foreach (getallheaders() as $name => $value) {
echo "$name: $value\n";
}
You can also use file_get_contents('php://input')
to get the body of the request
<?php
echo file_get_contents('php://input');
It's worth noting that some of the information in the $_SERVER
array may not be available in some server configurations.