Re: Register Globals

From: Date: Mon, 21 Jul 2003 16:26:02 +0000
Subject: Re: Register Globals
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-156089@lists.php.net to get a copy of this message
* Thus wrote stfmoreau (stfmoreau@yahoo.fr): > Hi, > > include this code in your header file : > // _GET > if (isset($_GET)) > while (list($key, $val) = each($_GET)) > { > eval ("$".$key." = '".$val."';"); > } > // _POST > if (isset($_POST)) > while (list($key, $val) = each($_POST)) > { > eval ("$".$key." = '".$val."';"); > } > // _SESSION > if (isset($_SESSION)) > while (list($key, $val) = each($_SESSION)) > { > eval ("$".$key." = '".$val."';"); > } > It may works (I have not expirimence it) You can shorten it down a bit: if (isset($_REQUEST) ) { foreach($_REQUEST as $key => $val) { $$key = $val; } } I'm not sure if session is there but I know the $_REQUEST has all GET, POST and COOKIE vars. Of course this isn't completely compatible with how register_globals works. There is GPC ordering of where to get the variables from. $GPC = "GPC" for($i = 0; i < strlen($GPC); $i++) { switch($GPC{$i}) { case 'G': $VAR = '_GET'; break; case 'P': $VAR = '_POST'; break; case 'C': $VAR = '_COOKIES'; break; } if (isset($$VAR) ) { foreach($$VAR as $key => $val) { eval("global $$key"); //make it global if this is in a function $$key = $val; //set value } } } Curt -- "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#156089) next »