Undo the harm done by register_globals set to on





18
Date Submitted Thu. Jul. 27th, 2006 4:56 AM
Revision 1 of 1
Helper rastersize
Tags "register | globals" | PHP
Comments 0 comments
This snippet will undo all the nasty stuff which happens when you set register_globals to on in your php.ini file.

(Originally found in the code of Wordpress).

// Let us unset all global variables set by register globals
if(ini_get('register_globals') == true)
{
        if(isset($_REQUEST['GLOBALS']))
                exit('GLOBALS overwrite attempt detected! Exiting...');
       
        // Variables that shouldn't be unset
        $noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
       
        $input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
        foreach($input as $k => $v)
                if(!in_array($k, $noUnset) && isset($GLOBALS[$k]))
                        unset($GLOBALS[$k]);
}
 

Aron C

jiart.org/
-----------------------
http://jiart.org/
My digital playground with it's own sandbox.
Well anyway, I love programming

Comments

There are currently no comments for this snippet.

Voting