How to edit the Register Globals setting without php.ini access
Posted by Support, Last modified by Support on 28 October 2008 03:00 PM

Emulating the Register Globals setting

PHP recommends that the PHP register_globals flag be turned off for performance and security reasons. Without direct access to the php.ini you might have issues in your PHP code with this. Below is PHP code to emulate the turning on and off of the register_globals flag.

Here is the code to emulate register_globals On.

<?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);
}
ini_set('register_globals', true);
}
?>


And this code will emulate register_globals Off.

<?php
// Emulate register_globals off
if (ini_get('register_globals')) {
$superglobals = array($_SERVER, $_ENV,
$_FILES, $_COOKIE, $_POST, $_GET);
if (isset($_SESSION)) {
array_unshift($superglobals, $_SESSION);
}
foreach ($superglobals as $superglobal) {
foreach ($superglobal as $global => $value) {
unset($GLOBALS[$global]);
}
}
ini_set('register_globals', false);
}
?>

(508 vote(s))
Helpful
Not helpful

Comments (0)