Print all Server header & POST request information using PHP.

When you start getting into web services and integration via APIs this will definitely come in handy. The HTTP protocol has a little more going on in the background not visible to the user. Besides serving pages there are other information useful to developers that is being send across when making HTTP requests.

Understanding what server values are being utilized by the browser in the background makes things a hell of allot easier to wrap your head around challenges that you may come across.

This is also very useful when you developing on micro controller platforms such as Arduino and ESP8266

Let’s start by creating a basic HTML form that will be posted to PHP page.


<form action="readpostform.php" method="post">
Username:<input type="text" name="name">
Password: <input type="text" name="email">
<input type="submit">


The above data will be posted to ‘readpostform.php’ and the raw data will be dumped to screen

So let’s create a file called readpostform.php

echo '<b>RAW DUMP</b><bR>';
echo var_dump( get_defined_vars() );

echo '<br><br><b>List of variables</b><br><table>'; 
    foreach ($_POST as $key => $value) {
        echo "<tr>";
        echo "<td>";
        echo $key;
        echo "</td>";
        echo "<td>";
        echo $value;
        echo "</td>";
        echo "</tr>";
echo '</table>';

   echo '<br><br><b>Server Variables</b><br>';
   while (list($var,$value) = each ($_SERVER)) {
      echo "$var => $value <br />";

The result should output something like this.

*Disclaimer, I copied the above code from across the internet and take no credit for this.


You May Also Like

About the Author: Martin Viljoen

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA ImageChange Image