可能重复:
PHP: the ultimate clean/secure function这段代码实际上是否可以用于SQL注入?
我发现这个代码片段在这里:http://snipplr.com/view/12853/clean-variables-from-sql-injections/
笔者主张:
这个小功能可以帮助对抗常见安全问题与SQL注入,它可以消毒任何像$ POST,$ GET,$ _SERVER等全局变量并转义不安全的字符。
此代码是否安全?
function _clean($str){
return is_array($str) ? array_map('_clean', $str) : str_replace("\\", "\\\\"
, htmlspecialchars((get_magic_quotes_gpc() ? stripslashes($str) : $str)
, ENT_QUOTES));
}
//usage call it somewhere in beginning of your script
_clean($_POST);
_clean($_GET);
_clean($_REQUEST);// and so on..
请告诉我这是否是安全的,“因为它看起来陪审团操纵我。
这是不安全的。 - – 2011-05-28 22:07:36
@Alix,我99%肯定 – Johan 2011-05-28 22:09:00
99%确定它是borken,即:-) – Johan 2011-05-29 20:25:28