Announcement

Collapse
No announcement yet.

Debug POST and GET submissions

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Debug POST and GET submissions

    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.

    Code:
    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!
    Need a mod for your game? I do work that is second to none. PM me for further details or click on my banner to view my website.

  • #2
    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...

    Comment


    • #3
      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
      Need a mod for your game? I do work that is second to none. PM me for further details or click on my banner to view my website.

      Comment

      Working...
      X