Miscellaneous Code

  Home arrow Miscellaneous Code arrow register_globals INI Setting Emulator
MISCELLANEOUS CODE

register_globals INI Setting Emulator
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2004-06-08

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    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.

    if(isset($GLOBALS["registerglobalsproxy"])) return;
    $GLOBALS["registerglobalsproxy"] = true;

    $oldErrorLevel = error_reporting(0);

    //**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.

    More Miscellaneous Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    MISCELLANEOUS CODE ARTICLES

    - Creating a Web Page Controller with the HMVC...
    - Coding Controllers and Views for the HMVC De...
    - A Sample Web Application with the HMVC Desig...
    - Adding a Class to Parse Views to an HMVC Des...
    - Building a Model Class for the HMVC Design P...
    - Filtering Input Data and Generating HTML For...
    - The HMVC Design Pattern: Working with MySQL ...
    - Dispatching Requests to MVC Triads with the ...
    - Implementing the Hierarchical Model-View-Con...
    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap