View Full Version : Debug POST and GET submissions

05-28-2008, 04:23 PM
I've found that one of the biggest problems with making forms that people have when things aren't working the way they intended, is that they don't know what's being sent from one script to another.

function _display($type = 'request') {
echo '<div align="left">';
if ($type == 'request') {
echo "<pre>". print_r($GLOBALS['_REQUEST'], 1). "</pre>";
} elseif ($type == 'all') {
echo "<pre>". print_r($GLOBALS, 1). "</pre>";
} elseif ($type == 'session') {
echo "<pre>". print_r($GLOBALS['_SESSION'], 1). "</pre>";
echo '</div>';

_display(); is a function I use a lot when things aren't working for me. It shows me exactly what is being sent in the form.
I can't stress enough how helpful it is to actually SEEEEEEEEEEEE what is being passed.

Once you see what is being passed, you'll most likely find that debugging your script becomes quite a bit easier.

This function has other uses as well. _display('all') shows you every variable you have set. very handy.....

_display('session') shows you everything set in your $_SESSION array.

Note that _display() shows you the REQUEST array which is a compilation of POST, GET, and COOKIE arrays.

Have fun with it!

06-07-2008, 08:48 PM
It's always useful to know what variables holds.
I normally just use var_dump, gives slightly more information about the variables(type, length) than print_r, but with a little playing with your function Floydian, I see how this is going to be very useful.

Nice function...

06-08-2008, 01:37 AM
Thanks ;)

That's right, you can add a second optional argument:

$function = 1

where if $function = 1, vardump is used, if $function = 2, print_r is used, and so on. or, it can simply be added to the switch, and the $type argument.

One could also pass the $ir (mccodes style) array and test if the person is staff level, in case this function is called and left in a script that is uploaded live. At least then, it wouldn't be visible to players ;)