note 48227 deleted from security.globals by aidan

From: Date: Sat, 15 Jan 2005 12:57:21 +0000
Subject: note 48227 deleted from security.globals by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-83305@lists.php.net to get a copy of this message
Note Submitter: alex at sourcelibre dot com ---- This is a simple function to make the register globals OFF and magic_quotes_gpc ON. aalex <?php function safe_php() { /** * Lets verify the PHP configuration. */ $register_globals = ini_get('register_globals'); $magic_quotes_gpc = ini_get('magic_quotes_gpc'); /** * Get super gloabals. We don't need $_SERVER, $_FILES and $_ENV. */ $superglobals = array('_GET', '_POST', '_COOKIE','_REQUEST'); /** * Now, let's clean it up ! */ foreach ($superglobals as $superglobal) { if (is_array($superglobal)) { foreach ($$superglobal as $key => $val) { /** * Unset global variables GET, POST and COOKIE if register_globals is on. */ if ($register_globals) { unset($GLOBALS[$key]); } /** * Make sure magic_quote_gpc is on, or addslashes() yourself if not. */ if (!$magic_quotes_gpc) { if (is_array($key)) { foreach($key as $a_key => $a_value) { $a_key =addslashes($a_value); $$superglobal['$key']['a_key'] = $a_key; } } else { $key =addslashes($value); $$superglobal['$key'] = $key; } } } } } return TRUE; } ?>

« previous php.notes (#83305) next »