This file emulates the bahaviour shown when register_globals is turned on. It is useful when you need to support code that requires automatic global variable creation without enabling it for a server or particular folder (using .htaccess). Any POST or GET variables are automatically created. Further global arrays can be added to the $methodsToParse table to allow for further support. Support for $_FILE uploads recently added.
By : wmfwlr
<? //** June 8, 2004 (wmfwlr<AT>cogeco<DOT>ca) //** ============================================ //** Added support for uploaded file variables.
//** May 31, 2004 (wmfwlr<AT>cogeco<DOT>ca) //** ============================================ //** Hack to act as though register_globals setting is enabled //** on server. Unsupported code.
//**HANDLE_FILE_VARIABLES_SEPARATELY****************************************** //** loop over the uploaded file array. Files need to be handled differently //** due the the fact that values returned are in an array, where as with //** register globals enabled they are not.
foreach($_FILES as $fileVar => $fileArray) { if(is_array($fileArray)) { //** for each uploaded file create a variable for each value in the //** upload array named 'filevarname_uploadedfilevalue'.
foreach($fileArray as $fileKey => $fileValue) { if(!is_numeric($fileKey)) { //** construct the name of the variable to create.
$newVarName = $fileVar . "_" . $fileKey;
//** dynamically set the variable value.
$$newVarName = $fileValue;
//** the server file path needs to be stored as this fileVar to support //** conventions of old version.
if($fileKey == "tmp_name") //** path to uploaded file. $$fileVar = $fileValue; //** store full server path. } } } } //**HANDLE_OTHER_SERVER_VARIABLES********************************************* //** arrays of variable storage methods to be parsed, in order of //** increasing trustworthyness.
$methodsToParse = array($_GET, $_POST);
foreach($methodsToParse as $method) { //** if the method is an array of variables attempt to set each //** associative key to its appropriate value.
if(is_array($method)) { foreach($method as $key => $value) { //** do not try to create any variables from indexes of arrays.
if(!is_numeric($key)) $$key = $value; } } } //** restore the error reporting when entered.
error_reporting($oldErrorLevel); ?>
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.