<?php
// *
// * DebugShowVars.php - Shows selected variable
// * arrays in the 'variable' iframe as defined
// * in the debug/index.php file.
// *
// * Project was written by Phil Petree
// * and is available at philpetree.com
// * and is released under GNU license.
// * Copyright (C) 2010 by Phill Petree. All rights reserved worldwide.
// * US Governement users have restricted rights.
// *
// * Ver 1.0 - Release date: June 22, 2010
// *
// *
// * special thanks to: kailashbadu at hotmail dot com
// *
/**
* @desc works out the variables in the current scope(from where function was called).
* Returns an array with variable name as key and vaiable value as value
* @param $varList: variables returned by get_defined_vars() in desired scope.
* $excludeList: variables to be excluded from the list.
* @return array
*/
function getDefinedVars($varList, $excludeList)
{
$temp1 = array_values(array_diff(array_keys($varList), $excludeList));
$temp2 = array();
while (list($key, $value) = each($temp1)) {
global $$value;
$temp2[$value] = $$value;
}
return $temp2;
}
/**
* @desc holds the variable that are to be excluded from the list.
* Add or drop new elements as per your preference.
* @var array
*/
$excludeList = array();
// start by adding in the deprecated variables (this prevents dups!)
$excludeList[] = 'HTTP_COOKIE_VARS'; // deprecated, replaced by $_COOKIES
$excludeList[] = 'HTTP_ENV_VARS'; // deprecated, replaced by $_ENV
$excludeList[] = 'HTTP_POST_FILES'; // deprecated, replaced by $_FILES
$excludeList[] = 'HTTP_POST_VARS'; // deprecated, replaced by $_POST
$excludeList[] = 'HTTP_SERVER_VARS'; // deprecated, replaced by $_SERVER
$excludeList[] = 'HTTP_GET_VARS'; // deprecated, replaced by $_GET
// there are a number of variables included in several lists including
// _SERVER, _ENV etc. and also outside of these globals. So, we'll add
// these to the total exclude list so that these only show up when we
// select one of the GLOBAL categories.
$excludeList[] = 'CONTENT_LENGTH';
$excludeList[] = 'CONTENT_TYPE';
$excludeList[] = 'DOCUMENT_ROOT';
$excludeList[] = 'GATEWAY_INTERFACE';
$excludeList[] = 'HTTP_ACCEPT';
$excludeList[] = 'HTTP_ACCEPT_ENCODING';
$excludeList[] = 'HTTP_ACCEPT_LANGUAGE';
$excludeList[] = 'HTTP_CACHE_CONTROL';
$excludeList[] = 'HTTP_CONNECTION';
$excludeList[] = 'HTTP_COOKIE';
$excludeList[] = 'HTTP_HOST';
$excludeList[] = 'HTTP_REFERER';
$excludeList[] = 'HTTP_USER_AGENT';
$excludeList[] = 'PATH';
$excludeList[] = 'QUERY_STRING';
$excludeList[] = 'REDIRECT_STATUS';
$excludeList[] = 'REMOTE_ADDR';
$excludeList[] = 'REMOTE_PORT';
$excludeList[] = 'REQUEST_METHOD';
$excludeList[] = 'REQUEST_URI';
$excludeList[] = 'SCRIPT_FILENAME';
$excludeList[] = 'SCRIPT_NAME';
$excludeList[] = 'SERVER_ADDR';
$excludeList[] = 'SERVER_ADMIN';
$excludeList[] = 'SERVER_NAME';
$excludeList[] = 'SERVER_PORT';
$excludeList[] = 'SERVER_PROTOCOL';
$excludeList[] = 'SERVER_SIGNATURE';
$excludeList[] = 'SERVER_SOFTWARE';
$excludeList[] = 'UNIQUE_ID';
$excludeList[] = 'PHP_SELF';
$excludeList[] = 'REQUEST_TIME';
if(!$_POST["GLOBALS"] )
{
$excludeList[] = 'GLOBALS';
}
if(!$_POST["_SERVER"] )
{
$excludeList[] = '_SERVER';
}
if(!$_POST["_GET"] )
{
$excludeList[] = '_GET';
}
if(!$_POST["_POST"] )
{
$excludeList[] = '_POST';
}
if(!$_POST["_FILES"] )
{
$excludeList[] = '_FILES';
}
if(!$_POST["_REQUEST"] )
{
$excludeList[] = '_REQUEST';
}
if(!$_POST["_SESSION"] )
{
$excludeList[] = '_SESSION';
}
if(!$_POST["_ENV"] )
{
$excludeList[] = '_ENV';
}
if(!$_POST["_COOKIE"] )
{
$excludeList[] = '_COOKIE';
}
if(!$_POST["php_errormsg"] )
{
$excludeList[] = 'php_errormsg';
}
if(!$_POST["HTTP_RAW_POST_DATA"] )
{
$excludeList[] = 'HTTP_RAW_POST_DATA';
}
if(!$_POST["http_response_header"] )
{
$excludeList[] = 'HTTP_RESPONSE_HEADER';
}
if(!$_POST["argc"] )
{
$excludeList[] = 'argc';
}
if(!$_POST["argv"] )
{
$excludeList[] = 'argv';
}
// Now exclude our exclusion list!
$excludeList[] = 'excludeList';
//some dummy variables; add your own or include a file.
// $firstName = 'kailash';
// $lastName = 'Badu';
// $test = array('Pratistha', 'sanu', 'fuchhi');
//get all variables defined in current scope
$varList = get_defined_vars();
echo "<h3>Only shows variables you have used!</h3>";
//Time to call the function
print "<pre>";
print_r(getDefinedVars($varList, $excludeList));
print "</pre>";
?>