Disabling PHP's register_globals in userland

Tagged:
So you have a large PHP deployment that is (still? - this is 2008!) using register_globals. How do you test individual pieces of the site without being able to change the ini variable via .htaccess? Try this code out:
<?php
if (ini_get('register_globals'))
{
        $__sgs = array('_ENV', '_GET', '_POST', '_COOKIE', '_SERVER');
        foreach ($__sgs as $__sg)
        {
                $__k = array_keys(${$__sg});
                foreach($__k as $__v)
                {
                        if (isset($$__v) && ${$__sg}[$__v] === $$__v)
                        {
                                unset($$__v);
                        } // end if superglobal var = local var
                } // end foreach superglobal key
        } // end foreach superglobal
} // end if register_globals
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is used to make sure you are a human visitor and to prevent spam submissions.
Syndicate content