note 39348 added to function.get-defined-vars

From: Date: Sun, 25 Jan 2004 17:26:29 +0000
Subject: note 39348 added to function.get-defined-vars
Groups: php.notes 
Request: Send a blank email to php-notes+get-64163@lists.php.net to get a copy of this message
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); ?> ---- Manual Page -- http://www.php.net/manual/en/function.get-defined-vars.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39348 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39348&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39348&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#64163) next »