Old PHP script in register global = off environment

My friend asked me how to run PHP scripts (which is written for register global = on environment) in a register global = off environment. Yeah, it’s a bad thing to write PHP script for register global = on environment, he just wanted his old scripts work with minimum efforts.

So I gave him a short script, which will regenerate variables from $_POST or $_GET. This script need to be placed onto the top of every single file which required variable from POST or GET method.

< ?php foreach($_POST as $key=>$value){
$$key = $value;
}
foreach($_GET as $key=>$value){
$$key = $value;
}
?>

Above script will, for example, generate variable named $username from $_POST[‘username’] with the same value.

Just remember to put above script in the top of your scripts, and remember NOT to write bad scripts.

In

One response

  1. yudhi Avatar
    yudhi

    mate’s,

    also,you can do like this :
    – create file .htaccess ,entry with this :

    php_flag register_globals on

    and then ,viola..

Leave a Reply

Verified by MonsterInsights