Addslashes是一种不安全的写法,有的字符会不全过滤掉
所以要用mysql_real_escape_string来过滤
[code]
// Quote variable to make safe
function quote_smart($value) {
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = (stripslashes($value));
}
// Quote if not integer
if (!is_numeric($value) || $value[0] == '0') {
$value = mysql_real_escape_string($value);
}
return $value;
}[/code]
说明:。
1.看看magic_quotes_gpc是否开,如果开就要去掉其' " NUL 前面的 转义,让mysql的转义来完成
2.用mysql的转义
最后要注意的是:
%和_也是个不安全的字符,尤其是在 SQL里有like 时,破坏性代码没试
参考:
http://cn.php.net/manual/zh/function.addslashes.php
http://www.php.net/manual/en/function.mysql-real-escape-string.php
http://www.php.net/manual/en/security.database.sql-injection.php
http://cn.php.net/manual/zh/function.mysql-real-escape-string.php