Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Emulate register_globals off

Here is a function that emulates register_globals off, if you can't disable it yourself, you can use this function in the beginning of the script:

<?php
// Emulate register_globals off
function unregister_GLOBALS()
{
    if (!ini_get('register_globals')) {
        return;
    }

    // Might want to change this perhaps to a nicer error
    if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
        die('GLOBALS overwrite attempt detected');
    }

    // Variables that shouldn't be unset
    $noUnset = array();

    $input = array_merge
            (
                $_GET,    $_POST,
                $_COOKIE, $_SERVER,
                $_ENV,    $_FILES,
                isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array()
            );
    
    foreach ($input as $k => $v) {
        if (!in_array($k, $noUnset) && isset($GLOBALS[$k])) {
            unset($GLOBALS[$k]);
        }
    }
}
unregister_GLOBALS();
?>

You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus