Copy/paste this into the top of your web page or save the code as phpDebugTool.php
and then include it using include(
. Then look at the source code after you’ve run the page.
<?php /* These lines format the output as HTML comments and call dump_array repeatedly */ echo "\n<!-- BEGIN VARIABLE DUMP -->\n\n"; echo "\n\n<!-- BEGIN GET VARS -->\n\n";echo "<!-- ".dump_array($_GET)." -->\n"; echo "\n\n<!-- BEGIN POST VARS -->\n\n";echo "<!-- ".dump_array($_POST)." -->\n"; echo "\n\n<!-- BEGIN SESSION VARS -->\n\n";echo "<!-- ".dump_array($_SESSION)." -->\n"; echo "\n\n<!-- BEGIN COOKIE VARS -->\n\n";echo "<!-- ".dump_array($_COOKIE)." -->\n"; echo "\n\n<!-- END VARIABLE DUMP -->\n\n"; function dump_array($array) { if(is_array($array)) { $size = count($array); $string = ""; if ($size) { $count = 0; $string .= "{ "; //loop thru key:value pairs foreach($array as $var => $value) { $string .= $var." = ".$value; if($count++ < ($size-1)) { $string .= ", "; } } $string .= " }"; } return $string; } else { return $array; } } ?>
An example of this in action can been seen on the Demo page.