Emulate Register Globals in php

let’s say you’re using php below 5.3 in which register_globals are automaticaly turned off for security reasons and one customer/website requires them for some older scripts they have.

You can emulate them so you don’t have to touch php options:

Note: This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.

Solution taken from: http://www.nasatech.com/PHP-DOCS/faq.misc.html#faq.misc.registerglobals

This will 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($superglobalEXTR_SKIP);
}
ini_set('register_globals'true);
}
?>

This 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);
}
?>