Alan Edwardes

GET/POST Spew In PHP with print_r()

Old Content Warning

This post is very old (it was published 4 years ago), so I can't vouch for its content or accuracy. It may be here for posterity. Please take its content with a pinch of salt.

Just a quick piece of PHP code to spew anything after the page URL, EG ?foo=bar&foo2=bar2. I find it useful to use from time to time where I uber fuck up a form element and can't be bothered to look back over my code to fix it. You could use $_GET and $_POST but using the $_REQUEST variable covers them both.

print_r($_REQUEST);

You can use the print_r (print recursively) on any array - so it works on superglobals like $_SERVER and $_COOKIE, which can be sometimes useful for debugging.

The $_COOKIE superglobal especially awesome as it lets you see any cookies that the script you're running the code from has access to, and their values.

You can also use it with your own arrays:

$pie = array('foo' => 'bar','one' => 'two');
print_r($pie);

Output

Array(
    [foo] => bar
    [one] => two
)

05th of May 2009 at 8:06 PM

4 years ago

I was 17 years old when I wrote this

141 words

rand: Google SearchWiki

next: Windows 7: A New ...

prev: It's fun to play ...

share:FacebookTwitterRedditdiggStumbleUpondeliciousHacker NewsLinkedIn

Add a Comment

© 2006 – 2013 Alan Edwardes / Source on GitHub
Top