Undo the harm done by register_globals set to on
18
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).
(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]);
}






There are currently no comments for this snippet.