±¾ÀýÄ£Äâ register_globals On¡£Èç¹û¸Ä±äÁËÅäÖÃÎļþÖÐµÄ variables_order Ñ¡ÏÔò¿¼ÂǶÔ
$superglobals ×÷³öÏàÓ¦µÄ¸Ä¶¯¡£
<?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);
}
}
?>
±¾ÀýÄ£Äâ register_globals Off¡£Òª¼Çס´Ë´úÂëÓ¦Ôڽű¾×ͷµÄµØ·½µ÷Óá£Èç¹ûʹÓÃÁ˻Ự»úÖÆ£¬ÔòÔÚ
session_start() Ö®ºóµ÷Óá£
<?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('GLOBALS', '_GET',
'_POST', '_COOKIE',
'_REQUEST', '_SERVER',
'_ENV', '_FILES');
$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();
?>