Created
November 15, 2015 11:16
-
-
Save mytory/25cd362bc470f5ae68c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Emulate register_globals off | |
// source: http://php.net/manual/en/faq.misc.php#faq.misc.registerglobals | |
function unregister_GLOBALS() | |
{ | |
if (!ini_get('register_globals')) { | |
return; | |
} | |
// Might want to change this perhaps to a nicer error | |
if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) { | |
die('GLOBALS overwrite attempt detected'); | |
} | |
// 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]); | |
} | |
} | |
} | |
unregister_GLOBALS(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment