Emulating "register_globals On"

Post your scripts here.

<b>Note:</b>The scripts must be your own, and please read the "Important: Read before you post" thread inside this category before participating here.
Locked
tanaka
Posts: 195
Joined: Sat Mar 05, 2005 5:27 pm

Emulating "register_globals On"

Post by tanaka »

For those who are having problems due to the change of register_globals to Off, here is a script that emulates register_globals as if it is On.
It's useful if you don't know what to do if your script shows any error because of register_globals or if you don't want to let your site offline while reprogramming the script.
Here it is:

Code: Select all

<?php
// Emulate register_globals on
if (!ini_get('register_globals')) {
   $superglobals = array($_SERVER, $_ENV,
       $_FILES, $_COOKIE, $_POST, $_GET);
   if (isset($_SESSION)) {
       array_unshift($superglobals, $_SESSION);
   }
   foreach ($superglobals as $superglobal) {
       extract($superglobal, EXTR_SKIP);
   }
}
?>
It should be put in the beginning of your script. I hope you like it. :)


L O L
mohumben
Posts: 82
Joined: Thu Sep 15, 2005 9:45 pm

Post by mohumben »

Please don't merely copy and paste stuff. Linking to the site is better:
http://www.weberdev.com/Manuals/PHP/faq.misc.html

register_globals is turned off by default for security reasons.
Use properly the $_POST , $_GET ... super globals instead of using this.
Locked