我从此脚本中收到此通知"Undefined variable: _ in magic_quotes_gpc.php on line 43"
:
<?php
$HTTP_VARs = array(
'HTTP_GET_VARS' => '_GET',
'HTTP_POST_VARS' => '_POST',
'HTTP_COOKIE_VARS' => '_COOKIE',
'HTTP_SERVER_VARS' => '!_SERVER',
'HTTP_ENV_VARS' => '!_ENV',
'HTTP_POST_FILES' => '!_FILES'
);
if (!isset($HTTP_GET_VARS) && isset($_GET)) {
foreach ($HTTP_VARs as $HTTP_VAR => $_VAR) {
$_VAR = ($_VAR[0] == '!' ? str_replace('!', '', $_VAR) : $_VAR);
if (isset($$_VAR))
$$HTTP_VAR = $$_VAR;
}
}
function strip_magic_quotes($array)
{
foreach ($array as $key => $value)
$array[$key] = (is_array($value) ? strip_magic_quotes($value) : stripslashes($value));
return $array;
}
foreach ($HTTP_VARs as $HTTP_VAR => $_VAR) {
if ($_VAR[0] != '!') {
if (get_magic_quotes_gpc()) {
if (!empty($$_VAR))
$$_VAR = strip_magic_quotes($$_VAR);
} else {
if (is_array($$_VAR)) {
foreach ($$_VAR as $k => $v) {
if (is_array($$_VAR[$k])) {
foreach ($$_VAR[$k] as $k2 => $v2)
$$_VAR[$k][$k2] = addslashes($v2);
@reset($$_VAR[$k]);
} else
$$_VAR[$k] = addslashes($v);
}
@reset($$_VAR);
}
}
}
}
?>
第43行是:if (is_array($$_VAR[$k]))
我使用echo来发布所有值,而不是单个1是_
。
我看了看,不知道这个变量_
来自哪里,我很困惑。
答案 0 :(得分:2)
WOA!我不知道你要用大量代码实现什么,但是你可以使用以下(更简单的)代码来处理魔术引号:
/** Recursive array version of stripslashes. */
function stripslashes_deep($value) {
$value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
return $value;
}
/** Remove magic quotes if enabled. */
function nuke_magic_quotes() {
if (get_magic_quotes_gpc()) {
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}
}