Page 1 of 1

Emulating "register_globals On"

Posted: Fri Sep 02, 2005 7:57 pm
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. :)

Posted: Fri Oct 07, 2005 12:36 am
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.