3月
21
当magic_quotes_gpc设置为1时,GPCF的数据将被addslashes。
这里是使用程序还原原始数据的代码,相当于把magic_quotes_gpc设置为0。
if (get_magic_quotes_gpc()) { // check magic_quotes_gpc state
function strip_quotes(&$var) {
if (is_array($var)
array_walk($var, 'strip_quotes');
else
$var = stripslashes($var);
}
// Handle GPC
foreach (array('GET','POST','COOKIE') as $v)
if (!empty(${"_".$v}))
array_walk(${"_".$v}, 'strip_quotes');
// Original file names may contain escaped data as well
if (!empty($_FILES))
foreach ($_FILES as $k => $v) {
$_FILES[$k]['name'] = stripslashes($v['name']);
}
或者更快的解决方法:
if (get_magic_quotes_gpc()) {
$in = array(&$_GET, &$_POST, &$_COOKIE);
while (list($k,$v) = each($in)) {
foreach ($v as $key => $val) {
if (!is_array($val)) {
$in[$k][$key] = stripslashes($val);
continue;
}
$in[] =& $in[$k][$key];
}
}
unset($in);
}
这里是使用程序还原原始数据的代码,相当于把magic_quotes_gpc设置为0。
if (get_magic_quotes_gpc()) { // check magic_quotes_gpc state
function strip_quotes(&$var) {
if (is_array($var)
array_walk($var, 'strip_quotes');
else
$var = stripslashes($var);
}
// Handle GPC
foreach (array('GET','POST','COOKIE') as $v)
if (!empty(${"_".$v}))
array_walk(${"_".$v}, 'strip_quotes');
// Original file names may contain escaped data as well
if (!empty($_FILES))
foreach ($_FILES as $k => $v) {
$_FILES[$k]['name'] = stripslashes($v['name']);
}
或者更快的解决方法:
if (get_magic_quotes_gpc()) {
$in = array(&$_GET, &$_POST, &$_COOKIE);
while (list($k,$v) = each($in)) {
foreach ($v as $key => $val) {
if (!is_array($val)) {
$in[$k][$key] = stripslashes($val);
continue;
}
$in[] =& $in[$k][$key];
}
}
unset($in);
}
Defined tags for this entry: php

0 引用