Register Globals workarounds
| From: | Justin French | Date: | Mon, 06 May 2002 00:55:35 +0000 |
| Subject: | Register Globals workarounds | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-96197@lists.php.net to get a copy of this message | ||
Hi all,
For those faced with the task of updating 100's or 1000's of pages that
assumed register_globals on, I've found a couple of solutions which can work
as a temporary solution whilst you re-engineer your pages (as I plan to do).
1. simple: ask your ISP to change php.ini :)
2. use a .htaccess file to change register_globals for your domain / dir, as
long as your Apache config file allows it.
http://www.php.net/manual/en/configuration.php
3. (untested) use ini_set() to turn them back on at a per-script or
per-config file level.
http://www.php.net/manual/en/function.ini-set.php
4. add this code to the top of your pages, or in a common library of code /
config file:
<?
foreach($GLOBALS as $key => $value)
{ $$key=$value; }
?>
If you have this url: page.php?foo=bah, with register_globals off, $foo will
not be available in your script automatically, as it was in older PHP
versions.
Using the above code, we scroll through the $GLOBALS array, and for each key
(eg foo) we assign a var of the same name (eg $foo) and assign it the
matching value (eg $foo = "bah").
The ultimate (secure) solution would be to get your code up to scratch with
the new set-up (and I plan to do this, ASAP), but I myself do not have time
for this, given that I have to update MANY sites within a short time frame,
and my ISP is planning a merge to the new version very soon.
I think foreach() was only available in newer versions of PHP though sorry.
Hope this helps.
Justin French
--------------------
Creative Director
http://Indent.com.au
--------------------