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).
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.
Here is the orignial data dump that I mentioned earlier
$_REQUEST variables:
| Key | Value |
| $_REQUEST variables | | $_GET vars | | | | $_POST vars | | | | $_COOKIE vars | | | | $_SERVER vars | | DOCUMENT_ROOT | /home/content/t/o/m/tomasvera/html | | GATEWAY_INTERFACE | CGI/1.1 | | HTTP_ACCEPT | text/html,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 | | HTTP_ACCEPT_CHARSET | ISO-8859-1,utf-8;q=0.7,*;q=0.7 | | HTTP_ACCEPT_ENCODING | gzip | | HTTP_ACCEPT_LANGUAGE | en-us,en;q=0.5 | | HTTP_CACHE_CONTROL | no-cache | | HTTP_CONNECTION | close | | HTTP_HOST | www.tomasvera.com | | HTTP_PRAGMA | no-cache | | HTTP_USER_AGENT | CCBot/1.0 (+http://www.commoncrawl.org/bot.html) | | HTTP_X_CC_ID | ccc02-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_STATUS | 200 | | REMOTE_ADDR | 38.107.191.96 | | REMOTE_PORT | 47810 | | REQUEST_METHOD | GET | | 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_URI | http://www.tomasvera.com/php/header_test.php | | SCRIPT_URL | /php/header_test.php | | SERVER_ADDR | 208.109.181.139 | | SERVER_ADMIN | support@supportwebsite.com | | SERVER_NAME | www.tomasvera.com | | SERVER_PORT | 80 | | SERVER_PROTOCOL | HTTP/1.1 | | SERVER_SIGNATURE | Apache/1.3.33 Server at www.tomasvera.com Port 80
| | SERVER_SOFTWARE | Apache | | SPI | TRUE | | PHP_SELF | /php/header_test.php | | REQUEST_TIME | 1283961771 | | | | $_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!
|