Jump to content

Debug POST and GET submissions


Recommended Posts

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!

Link to comment
Share on other sites

  • 2 weeks later...

Re: Debug POST and GET submissions

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...

Link to comment
Share on other sites

Re: Debug POST and GET submissions

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 ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...