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.
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:
Example of using the $_SERVER superglobal array to access information about the current HTTP request in PHP
<?php
print_r($_SERVER);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:
Example of using the $_SERVER superglobal array access specific information from the HTTP request in PHP
echo $_SERVER['REQUEST_METHOD'];To print the headers you could use:
Example of using the $_SERVER superglobal array to print the headers in PHP
<?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
Example of using the file_get_contents() function to get the body of the request in PHP
<?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.