A few debug functions based on a function I got off php.net (original function is included - it is from user notes on php.net)
By : Taoism
<?php /** * a variable to control whether debug code is displayed or not * * @param boolean $debug boolean to toggle debug code showing or not showing * */ $debug=true; //$debug=false;
/** * simple debug function * * got this function from the user-feedback section for the * print_r php function on www.php.net * its very useful for debugging * * @param mixed $call a variable to be dumped for display * @param string $cname a string to describe variable being dumped * * */ function dp($call,$cname) { global $debug; if($debug){ echo "<br/>".$cname.":<pre>"; if(!is_array($call)){$call=htmlspecialchars($call);} print_r($call); if(is_array($call)){reset($call);} echo "</pre><hr/>\n"; }//end function dp() ====================== }//end dp
/** * a function to display multiple variables side-by-side * * an extended version of dp() * it takes an array in and dynamically creates variable names * based on the array passed in so that side-by-side * comparissons of variables can be done. * this is most useful for comparing scopes... * i.e. the $_POST scope to the $_SESSION scope... * example of a call: * dpa(array('xvar'=>'$xvar','AUTH'=>'$AUTH','tmp_AUTH_admin'=>'$tmp_AUTH_admin','x'=>'array_intersect($AUTH["xvar"],$xvar)')); * Note that the key=>val pairs are VARNAME=>LABLE_TO_DESCRIBE. * The varname has no $ so that it can be dynamically called within the function * * @author Keith Young * @version 1.0 * @param array $dbug an array of key=>var pairs where the key is a variable name with no $, and the var is a lable to describe the key * @global boolean $debug used to check if the function should run or not * @global mixed $key this is a mixed data type based on the key value of the array passed in. * * @see dp() * */ function dpa($dbug) { global $debug; echo '<br/>'; foreach($dbug as $key=>$val){global ${$key};} if($debug){ $rspan=count($dbug); ($rspan==0)?$colpct=100:$colpct=100/$rspan; echo '<table cellspacing="2" cellpadding="5" width="75%" style="background-color:black;">'."\n"; echo '<tr><th colspan="'.$rspan.'" style="background-color:lightgrey;font-size:11pt; font-family:"Verdana";font-weight:bold;color:black;"> D E B U G : </th></tr>'."\n"; echo '<tr>'."\n";
/** * a function to display multiple variables side-by-side with the datatype of each variable displayed as well * * an extended version of dp() * it takes an array in and dynamically creates variable names based on the array passed in so that side-by-side * comparissons of variables can be done. * this is most useful for comparing scopes... * i.e. the $_POST scope to the $_SESSION scope... * This function also displays the datatype of each variable * example of a call: * dpa(array('xvar'=>'$xvar','AUTH'=>'$AUTH','tmp_AUTH_admin'=>'$tmp_AUTH_admin','x'=>'array_intersect($AUTH["xvar"],$xvar)')); * Note that the key=>val pairs are VARNAME=>LABLE_TO_DESCRIBE. * The varname has no $ so that it can be dynamically called within the function * * @author Keith Young * @version 1.0 * @param array $dbug an array of key=>var pairs where the key is a variable name with no $, and the var is a lable to describe the key * @global boolean $debug used to check if the function should run or not * @global mixed $key this is a mixed data type based on the key value of the array passed in. * * @see dp() * */ function vdpa($dbug) { global $debug; echo '<br/>'; foreach($dbug as $key=>$val){global ${$key};} if($debug){ $rspan=count($dbug); ($rspan==0)?$colpct=100:$colpct=100/$rspan; echo '<table cellspacing="2" cellpadding="5" width="75%" style="background-color:black;">'."\n"; echo '<tr><th colspan="'.$rspan.'" style="background-color:lightgrey;font-size:11pt; font-family:"Verdana";font-weight:bold;color:black;"> D E B U G : </th></tr>'."\n"; echo '<tr>'."\n";
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.