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) {
       return;
    }
 
// Save the existing superglobals first
    $REQUEST = $_REQUEST;
    $GET = $_GET;
    $POST = $_POST;
    $COOKIE = $_COOKIE;
 
    if (isset($_SESSION)) {
        $SESSION = $_SESSION;
    }
 
    $FILES = $_FILES;
    $ENV = $_ENV;
    $SERVER = $_SERVER;
 
// Unset the $GLOBALS array (clear all)
    foreach($GLOBALS as $key => $value) {
        if ($key != 'GLOBALS') {
            unset($GLOBALS[$key]);
        }
    }
 
// Re-assign the saved superglobals again
    $_REQUEST = $REQUEST;
    $_GET = $GET;
    $_POST = $POST;
    $_COOKIE = $COOKIE;
 
    if (isset($SESSION)) {
        $_SESSION = $SESSION;
    }
 
    $_FILES = $FILES;
    $_ENV = $ENV;
    $_SERVER = $SERVER;
}
 

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>