From: Chuck Hagenbuch Date: Wed, 23 Sep 2009 20:47:01 +0000 (-0400) Subject: Toss some of the random environment setup code into a separate class. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=2f259d0c57cf0f55f09fe21d32cdeea08a495fe1;p=horde.git Toss some of the random environment setup code into a separate class. --- diff --git a/framework/Rampage/lib/Horde/Rampage/Environment.php b/framework/Rampage/lib/Horde/Rampage/Environment.php new file mode 100644 index 000000000..28e590919 --- /dev/null +++ b/framework/Rampage/lib/Horde/Rampage/Environment.php @@ -0,0 +1,73 @@ +reverseMagicQuotes(); + $this->reverseRegisterGlobals(); + } + + /** + * @author Ilia Alshanetsky + */ + public function reverseMagicQuotes() + { + if (get_magic_quotes_gpc()) { + $input = array(&$_GET, &$_POST, &$_REQUEST, &$_COOKIE, &$_ENV, &$_SERVER); + + while (list($k, $v) = each($input)) { + foreach ($v as $key => $val) { + if (!is_array($val)) { + $key = stripslashes($key); + $input[$k][$key] = stripslashes($val); + continue; + } + $input[] =& $input[$k][$key]; + } + } + + unset($input); + } + } + + /** + * Get rid of register_globals variables. + * + * @author Richard Heyes + * @author Stefan Esser + * @url http://www.phpguru.org/article.php?ne_id=60 + */ + public function reverseRegisterGlobals() + { + if (ini_get('register_globals')) { + // 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) ? $_SESSION : array() + ); + + foreach ($input as $k => $v) { + if (!in_array($k, $noUnset) && isset($GLOBALS[$k])) { + unset($GLOBALS[$k]); + } + } + } + } +}