A Selective Register Gloabls Function for PHP
A friend was lamenting the lack of register_globals in his PHP setup (a tad late, as it became non-default back in April 2002). While register_globals was terrible in terms of security, it did excel in its simplicity.
function register_my_globals($allowed, $first, $second = array()) { $vars = array_intersect_key( array_merge($first, $second), array_combine($allowed, $allowed)); foreach ($vars as $key => $value) $GLOBALS[$key] = $value; } // First parameter defines allowed variables // The second and third are arrays in which to look for these keys. // Keys in the third array override keys in the first. register_my_globals(array('green', 'blue'), $_GET, $_POST); // Take variables only from POST data register_my_globals(array('cake'), $_POST);
The above snippet allows you to recreate the behaviour of register_globals, but on a case-by-case basis. You must specify the names of the variables you wish to allow, and the source arrays you’d like them taken from (almost always either HTTP GET parameters, or HTTP POST data).

