Simulare i registri globali disabilitati con PHP

Se non volete (o non potete) modificare il php.ini per disabilitare i registri globali, questa funzione PHP vi ritornerÓ molto utile in quanto sarÓ possibile simulare i registri globali disabilitati.

function unregister_globals() {
    if (ini_get('register_globals') == 0) {
// Save the existing superglobals first
    $GET = $_GET;
    $POST = $_POST;
    if (isset($_SESSION)) {
        $SESSION = $_SESSION;
    $FILES = $_FILES;
    $ENV = $_ENV;
// Unset the $GLOBALS array (clear all)
    foreach($GLOBALS as $key => $value) {
        if ($key != 'GLOBALS') {
// Re-assign the saved superglobals again
    $_GET = $GET;
    $_POST = $POST;
    if (isset($SESSION)) {
        $_SESSION = $SESSION;
    $_FILES = $FILES;
    $_ENV = $ENV;

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>