Header Test

I originally created this page while I was trying to lear a thing or two about PHP. Since then I've become a .NET programmer and don't do much with PHP. However, I'm always trying to learn new things.

Originally, this page simply dumped out all the available request and server variables available to this page. That output is still visible at the bottom of this page.

But, now, I've added the following sections which are what people were hoping to find when they first landed on this page.

Parsing Posted Forms

Here is a form that will post back onto this page for processing. Fill out the form and click the "Submit" button (nothing gets stored, it is just sample data).

Favorite food:
Programmer:
 
Programming Languages:



Age:

Getting a Specific Value

To get the value of a specific key that you want, you can simply use syntax such as

echo($_POST["key_name"]);

If you haven't already, submit the form above, to see the value of the "favorite_food" input.

Parsing Query Strings

Next, I'd like to go over parsing information passed in the query string.

For the true newbies (I'm guessing there's a few reading this page), a Query String is the information that is appended to a page name when making a page request.

For Example, in "http://www.tomasvera.com/header_test.php?key1=value1&key2=value2" the bold text is the query string. Here's a link to a Wikipedia entry on the topic: http://en.wikipedia.org/wiki/Query_string

Here's a link that will reload this page and allow you to see this in action:
Submit For Parsing.

You will notice that the code is almost identical to the code used to parse the form, above. The reason for this is at the Form's information and the QueryString information is passed to the page as a Name-Value Pair collection.

Once you have a "handle" to the collection, you can simply iterate through the collection to find the value you want or dump out all the values, as I have done in these examples.

Well, that's a quick-n-dirty on parsing form and query string submissions in PHP. I hope you found this useful.

If you have any comments or questions, you may Contact me via this site.

Was this useful?;
Comments:

Here is the orignial data dump that I mentioned earlier

$_REQUEST variables:

KeyValue
$_REQUEST variables
$_GET vars
 
$_POST vars
 
$_COOKIE vars
 
$_SERVER vars
DOCUMENT_ROOT/home/content/t/o/m/tomasvera/html
GATEWAY_INTERFACECGI/1.1
HTTP_ACCEPTtext/html,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
HTTP_ACCEPT_CHARSETISO-8859-1,utf-8;q=0.7,*;q=0.7
HTTP_ACCEPT_ENCODINGgzip
HTTP_ACCEPT_LANGUAGEen-us,en;q=0.5
HTTP_CACHE_CONTROLno-cache
HTTP_CONNECTIONclose
HTTP_HOSTwww.tomasvera.com
HTTP_PRAGMAno-cache
HTTP_USER_AGENTCCBot/1.0 (+http://www.commoncrawl.org/bot.html)
HTTP_X_CC_IDccc02-02
PATH/bin:/usr/bin:/usr/local/bin
PATH_INFO/php/header_test.php
PHPRC/home/content/t/o/m/tomasvera/html
QUERY_STRING
REDIRECT_STATUS200
REMOTE_ADDR38.107.191.96
REMOTE_PORT47810
REQUEST_METHODGET
REQUEST_URI/php/header_test.php
SCRIPT_FILENAME/home/content/t/o/m/tomasvera/html/php/header_test.php
SCRIPT_NAME/php/header_test.php
SCRIPT_URIhttp://www.tomasvera.com/php/header_test.php
SCRIPT_URL/php/header_test.php
SERVER_ADDR208.109.181.139
SERVER_ADMINsupport@supportwebsite.com
SERVER_NAMEwww.tomasvera.com
SERVER_PORT80
SERVER_PROTOCOLHTTP/1.1
SERVER_SIGNATURE
Apache/1.3.33 Server at www.tomasvera.com Port 80
SERVER_SOFTWAREApache
SPITRUE
PHP_SELF/php/header_test.php
REQUEST_TIME1283961771
 
$_ENV vars
 
$_FILES vars
 

So... you've read this far. That means you're either pretty easily amused, or you are actually curious about this. So, Here's the source code use to generate the table above.

Hopefully, you will find this useful.

echo('<tr class="TableCell"><td colspan="2">$_REQUEST variables</td></tr>');

foreach($_REQUEST as $key=>$value)
echo("<tr><td>$key</td><td>$value</td></tr>");


echo('<tr class="TableCell"><td colspan="2">$_GET vars</td></tr>');
foreach($_GET as $key=>$value)
echo("<tr><td>$key</td><td>$value</td></tr>");
echo ('<tr><td colspan="2"> </td></tr>');

echo('<tr class="TableCell"><td colspan="2">$_POST vars</td></tr>');
foreach($_POST as $key=>$value)
echo("<tr><td>$key</td><td>$value</td></tr>");
echo ('<tr><td colspan="2"> </td></tr>');


echo('<tr class="TableCell"><td colspan="2">$_COOKIE vars</td></tr>');
foreach($_COOKIE as $key=>$value)
echo("<tr><td>$key</td><td>$value</td></tr>");
echo ('<tr><td colspan="2"> </td></tr>');


echo('<tr class="TableCell"><td colspan="2">$_SERVER vars</td></tr>');
foreach($_SERVER as $key=>$value)
echo("<tr><td>$key</td><td>$value</td></tr>");
echo ('<tr><td colspan="2"> </td></tr>');


echo('<tr class="TableCell"><td colspan="2">$_ENV vars</td></tr>');
foreach($_ENV as $key=>$value)
echo("<tr><td>$key</td><td>$value</td></tr>");
echo ('<tr><td colspan="2"> </td></tr>');


echo('<tr class="TableCell"><td colspan="2">$_FILES vars</td></tr>');
foreach($_FILES as $key=>$value)
echo("<tr><td>$key</td><td>$value</td></tr>");
echo ('<tr><td colspan="2"> </td></tr>');

Who know that you were sending this much information about yourself to who-knows-what website every time you visit a web site!