PDA
Partners

View Full Version : HowTo: Easily emulate register_globals = on


ZYV
January 5th, 2004, 02:02 PM
Hi,

If you are having problems with register_global = off there is an easy way to emulate the "on" setting:

extract($_COOKIE); extract($_POST); extract($_GET);

Note that the order is important! (GPC -> CPG).

Nevertheless I recommend you to convert your scripts to work with rg = off for enhanced security.

ZYV
January 5th, 2004, 04:29 PM
... and do not forget about $_SERVER, $_ENV, $_FILES, $_REQUEST and other superglobals.

Allin1Joe
January 16th, 2004, 12:23 AM
Here is what I put at the top of all my PhP programs...


if (!empty($_GET))
{
extract($_GET);
}
else if (!empty($HTTP_GET_VARS))
{
extract($HTTP_GET_VARS);
}

if (!empty($_POST))
{
extract($_POST);
}
else if (!empty($HTTP_POST_VARS))
{
extract($HTTP_POST_VARS);
}

ZYV
January 16th, 2004, 06:32 AM
In my opinion, something like

if (!get_cfg_var("register_globals")) {
...
}

is more handy and appropriate then !empty($_GET) stuff :)

HTH,
Z.

Allin1Joe
January 16th, 2004, 08:37 AM
Maybe, but this way I don't bother exploding if the array is empty.

However, at this point, I think we are debating the difference between a nickel and 5 pennies :)

ZYV
January 16th, 2004, 09:54 AM
Originally posted by Allin1Joe
However, at this point, I think we are debating the difference between a nickel and 5 pennies :)

Heh, yep, you are right :D

RedefinedMedia
January 16th, 2004, 01:43 PM
ive always used this 1 command to update old scripts


import_request_variables("GPC", "");


http://us4.php.net/import_request_variables

it basically is the same as running the export on all three just a little cleaner and smaller

Allin1Joe
January 16th, 2004, 01:45 PM
Originally posted by RedefinedMedia
ive always used this 1 command to update old scripts


import_request_variables("GPC", "");


http://us4.php.net/import_request_variables

it basically is the same as running the export on all three just a little cleaner and smaller

Great info, thanks!

ZYV
January 16th, 2004, 03:44 PM
Originally posted by RedefinedMedia
ive always used this 1 command to update old scripts

Heh, cool! I didn't know about that. But you will always have to add extract($_SERVER); because most of those old scripts use $PHP_SELF as well.