php开发安全程序
魔法引用magic_quotes_gpc
PHP提供magic_quotes_gpc魔法引用功能来保护我们的网站系统免受攻击,它会自动从用户的输入串中过滤特殊字符(’,”,\,\0 (NULL)),并减慢输入的过程。
检查使用magic_quotes_gpc的代码样例:
if (get_magic_quotes_gpc()) { //检查magic_quotes_gpc的打开状态
function strip_quotes(&$var) {
if (is_array($var){
array_walk($var, ‘strip_quotes’);
} else{
$var = stripslashes($var);
}
}//end func
// 处理GPC
foreach (array(‘GET’,’POST’,’COOKIE’) as $v){
if (!empty(${“_”.$v})){
array_walk(${“_”.$v}, ‘strip_quotes’);
}
}
// 处理上传时的文件名称
if (!empty($_FILES)){
foreach ($_FILES as $k => $v) {
$_FILES[$k]['name'] = stripslashes($v['name']);
}
}
}
PHP提供这个参数的初衷是好的,但是该功能从出现以来一直备受争议。实践表明,如果采用magic_quotes_gpc,则与不使用该函数相比,需要两倍多的内存来处理每条输入的元素,因此,如果非必要,我们可以在php.ini文件把该参数设置为关闭,不使用该功能,转用其他的方法为来处理。
其他高效的解决方案
由于magic_quotes_gpc的效率较低,我们使用其他方法来代替magic_quote_gpc魔法引用的功能,如下脚本:
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);
}
i hope so
what a nice post.what a great website
) thanks
This is a fine example.
I guess I had to think more about what you wrote before i can comment on it..
Have a great day.
LOADS OF SUNSHINE TO BE ON YOU TODAY.
Whoop whoop. I have a feeling this is becoming the best.Keep it up!:)
Even though it will not be here tomorrow, the effect of it will.
Hallelujah!
These words mean a great deal to me today. Truly, it is necessary to let go – I see that.
Well that’s a honest and true quotation
It’s heroic.It is as the candle burns itself to give light to others.