note 39347 deleted from function.array-search by tomsommer
| From: | tomsommer@php.net | Date: | Sun, 25 Jan 2004 17:45:28 +0000 |
| Subject: | note 39347 deleted from function.array-search by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-64167@lists.php.net to get a copy of this message | ||
Note Submitter: electronerd@hotmail.com
----
If you are one of the many who think register_globals is the worst thing ever to happen to PHP, here
is some code to clean your namespace. Put it at global scope, and it will obliterate any variables
not in the safelist array. I have populated my array with the superglobals corresponding to the
register_globals variables, so you can still access the data, but it poses much less of a threat.
<?php
$var_list = get_defined_vars();
$safelist = array('_GET', '_POST', '_COOKIE', '_SERVER',
'_ENV', '_FILES', '_REQUEST');
foreach($var_list as $name => $value)
{
if(array_search($name, $safelist) === FALSE)
{
unset($$name);
}
}
unset($var_list, $name, $value, $safelist);
?>
If you empty the safelist, your namespace will be completely clean.