Sample Code: Test Variable Dump
Hello, I thought I would post this here for others to use.
This is a script that will spit out all the data contained in the following variables:
$_SERVER, $_COOKIE, $_ENV, $_REQUEST, $_POST, and $_GET
Then at the bottom of the page, there are 2 links back to the same page, one with a query string, one without. Also there are two forms, one a POST, one a GET, each with sample of form items.
This can be nice for checking things or just seing what you can get from the variables.
Enjoy!
-Greg
<?php
<html>
<head>
<title>Test Variable Dump</title>
</head>
<body>
<table border=\"1\" width=\"100%\"><tr><th colspan=\"2\">$_SERVER data</th></tr>
foreach ($_SERVER as $key => $value)
print \"<tr><td>$key</td><td>$value</td></tr>\n\"; </table>
<br>
<table border=\"1\" width=\"100%\"><tr><th colspan=\"2\">$_COOKIE data</th></tr>
foreach ($_COOKIE as $key => $value)
print \"<tr><td>$key</td><td>$value</td></tr>\n\"; </table>
<br>
<table border=\"1\" width=\"100%\"><tr><th colspan=\"2\">$_ENV data</th></tr>
foreach ($_ENV as $key => $value)
print \"<tr><td>$key</td><td>$value</td></tr>\n\"; </table>
<br>
<table border=\"1\" width=\"100%\"><tr><th colspan=\"2\">$_REQUEST data</th></tr>
foreach ($_REQUEST as $key => $value)
print \"<tr><td>$key</td><td>$value</td></tr>\n\"; </table>
<br>
<table border=\"1\" width=\"100%\"><tr><th colspan=\"2\">$_POST data</th></tr>
foreach ($_POST as $key => $value)
print \"<tr><td>$key</td><td>$value</td></tr>\n\"; </table>
<br>
<table border=\"1\" width=\"100%\"><tr><th colspan=\"2\">$_GET data</th></tr>
foreach ($_GET as $key => $value)
print \"<tr><td>$key</td><td>$value</td></tr>\n\"; </table>
<hr><h3>PROCESS NEW DATA</h3>
<table border=\"1\">
<tr>
<th>Plain Links</th>
<th>Form; Method=GET</th>
<th>Form; Method=POST</th>
</tr>
<tr>
<td>
<a href=\"= $_SERVER['PHP_SELF'] \">Plain Link Back Here</a><br>
<a href=\"= $_SERVER['PHP_SELF'] ?test=1&answer=whatever\">Link
w/QueryString: <i><b>test=1&answer=whatever</b></i></a>
</td>
<td>
<form action=\"= $_SERVER['PHP_SELF'] \" method=\"GET\">
tbtest <input type=\"text\" name=\"tbtest\"><br>
<input type=\"checkbox\" name=\"cbtest\" value=\"1\"> 1
<input type=\"checkbox\" name=\"cbtest\" value=\"2\"> 2
<input type=\"checkbox\" name=\"cbtest\" value=\"3\"> 3<br>
<input type=\"radio\" name=\"rbtest\" value=\"1\"> 1
<input type=\"radio\" name=\"rbtest\" value=\"2\"> 2
<input type=\"radio\" name=\"rbtest\" value=\"3\"> 3 <br>
Pick Some: <select name=\"seltest\" multiple>
<option value=\"sel01\">Item 1</option>
<option value=\"sel02\">Item 2</option>
<option value=\"sel03\">Item 3</option>
<option value=\"sel04\">Item 4</option>
</select><br>
<input type=\"submit\" name=\"submit\" value=\"Submit via GET\">
<input type=\"reset\" name=\"reset\" value=\"Clear Form\">
</form>
</td>
<td>
<form action=\"= $_SERVER['PHP_SELF'] \" method=\"POST\">
tbtest <input type=\"text\" name=\"tbtest\"><br>
<input type=\"checkbox\" name=\"cbtest\" value=\"1\"> 1
<input type=\"checkbox\" name=\"cbtest\" value=\"2\"> 2
<input type=\"checkbox\" name=\"cbtest\" value=\"3\"> 3<br>
<input type=\"radio\" name=\"rbtest\" value=\"1\"> 1
<input type=\"radio\" name=\"rbtest\" value=\"2\"> 2
<input type=\"radio\" name=\"rbtest\" value=\"3\"> 3 <br>
Pick Some: <select name=\"seltest\" multiple>
<option value=\"sel01\">Item 1</option>
<option value=\"sel02\">Item 2</option>
<option value=\"sel03\">Item 3</option>
<option value=\"sel04\">Item 4</option>
</select><br>
<input type=\"submit\" name=\"submit\" value=\"Submit via GET\">
<input type=\"reset\" name=\"reset\" value=\"Clear Form\">
</form>
</td>
</tr>
</table>
</body></html>
?>
JeevesBond posted this at 21:30 — 21st July 2005.
He has: 3,956 posts
Joined: Jun 2002
Cheers man! Useful
Greg K posted this at 00:55 — 17th May 2006.
He has: 2,145 posts
Joined: Nov 2003
I knew I had posted this on here somewhere. Thought while I was grabbing the code, I would bump it so newer users would find it easier.
-Greg
PS. I just noticed the Submit buttons both say "Submit via GET", the second one should have said POST.
Abhishek Reddy posted this at 04:16 — 17th May 2006.
He has: 3,348 posts
Joined: Jul 2001
I'd love to see this as a class|module|package with a very simple interface (a few one-liners).
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.