|
|
|
|
|
|
| |
This example comes in handy when you need to get a full list of all current state global variables anywhere in your script. The lists will be printed with code highlighting for easy viewing:). Useful for debugging in your browser.
The function simply dumps out a list of $_POST, &_GET, $_SESSION, $_REQUEST, $_COOKIE, $_ENV and $_FILE if available.
Just call <? echo dump_vars(); die; ?> anywhere in your code that you want the current variable state dumped.
There are many better solutions to help with debugging, but this is a quick way to get an applications current state.
This could be adapted to support 3d arrays also!!
| <?php
function f_arr($arr) {
$fr = "<font color=red size=1>";
$fg = "<font color=green size=1>";
$fb = "<font color=blue size=1>";
$fk = "<font color=black size=1>";
$fe = "</font>";
$l = "$fg [ $fe";
$r = "$fg ] $fe";
$a = "$fk => $fe";
if(is_array($arr)) {
foreach($arr as $k=>$v){
$out[] = $l.$fb.$k.$fe.$r.$a.$fr.$v.$fe;
}
}
if(is_array($out)) {
return implode("<br />", $out);
} else {
return false;
}
}
function dump_vars() {
$out = "";
if($a = f_arr($_SESSION)) {
$out .= "SESSION[] ( <br><blockquote> $a </blockquote>) <br>";
}
if($a = f_arr($_REQUEST)) {
$out .= "REQUEST[] ( <br><blockquote> $a </blockquote>) <br>";
}
if($a = f_arr($_POST)) {
$out .= "POST[] ( <br><blockquote> $a </blockquote>)
<br>";
}
if($a = f_arr($_GET)) {
$out .= "GET[] (<br><blockquote> $a </blockquote>)<br>";
}
if($a = f_arr($_COOKIE)) {
$out .= "COOKIE[] (<br><blockquote> $a </blockquote>)
<br>";
}
if($a = f_arr($_ENV)) {
$out .= "ENV[] (<br><blockquote> $a </blockquote>)<br>";
}
if($a = f_arr($_FILES)) {
$out .= "FILES[] (<br><blockquote> $a </blockquote>)
<br>";
}
return $out;
}
?> | |
Example Usage:
| <?php
echo dump_vars();
die;
?> | | |
|
| Include a file inside of a function and have the included variables be global. Categories : PHP, Variables, Global Variables | | | How to make sure a that $foo is from a cookie and not from the URI. Categories : PHP, Variables, Global Variables, Cookies | | | Initialize global variables for every field in a table.
This version requires that phplib is installed on your
server. Categories : Global Variables, MySQL, PHP, Variables | | | Make old style (PHP3) scripts using GET, POST, COOKIE and File uploads (POST) compatible with
PHP 4.2.0 Categories : PHP, HTML and PHP, Global Variables, Cookies, Variables | | | Simple script to passing persistent and growing array between recalls of one page (manipulate little stack). Categories : Arrays, Global Variables, PHP, HTML and PHP, Variables | | | getting the name of the current script and query string Categories : PHP, Global Variables, Variables, URLs | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | clearing variables in php3 Categories : Variables, Arrays, PHP | | | A simple function to prevent undefined $_POST/$_GET/$_SESSION variable errors Categories : PHP, Variables, Errors and Logging | | | This functions compares the current PHP version with a
desired version. Because of the 3 tiered version system, a
direct compare of a string to phpversion() will not be
accurate. Categories : PHP Configuration, PHP, Variables | | | How to control the number of decimal places when outputting numbers. Categories : PHP, Strings, Variables | | | Functions to read a template file and fill in PHP variables. It will also fill in array variables, displaying parts of the template multiple times.
Categories : PHP, Variables, Filesystem | | | Newbie Notes #5 - To double quote, or single quote, that is the question Categories : PHP, Beginner Guides, Variables | | | A quick way set data from a form to a function or other places where you can lose scope. Categories : PHP, HTML and PHP, Variables | | | Display variables when a form is submitted using POST/GET Categories : PHP, Functions, Variables, Debugging | |
|
|
|