Php 过时的SQL注入防止器?
在我在Online上找到的登录脚本中,创建者添加了此函数以防止SQL注入攻击Php 过时的SQL注入防止器?,php,mysql,sql,Php,Mysql,Sql,在我在Online上找到的登录脚本中,创建者添加了此函数以防止SQL注入攻击 function Fix($str) { $str = trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } 自从我读到magic\u quotes\u gpc被(或已经)删除后,感觉这个函数有点过时了。
function Fix($str) {
$str = trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
自从我读到
magic\u quotes\u gpc
被(或已经)删除后,感觉这个函数有点过时了。不仅仅是简单地使用mysqli\u real\u escape\u string($user\u input)增加足够的安全性吗?mysql\u real\u escape\u string
在所有情况下都是不够的,但它绝对是非常好的朋友。更好的解决方案是使用
//example from http://php.net/manual/en/pdo.prepared-statements.php
$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (?, ?)");
$stmt->bindParam(1, $name);
$stmt->bindParam(2, $value);
// insert one row
$name = 'one';
$value = 1;
$stmt->execute();
另外,不要忘记可用于丢弃任何无效/可疑字符的
//example from http://php.net/manual/en/pdo.prepared-statements.php
$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (?, ?)");
$stmt->bindParam(1, $name);
$stmt->bindParam(2, $value);
// insert one row
$name = 'one';
$value = 1;
$stmt->execute();
mysql\u real\u escape\u string()
同样的问题影响
addslashes()
Chris Shiflett(安全专家)的回答在5.3中被弃用,在5.4中被删除。如果您的代码是用于分发的(即,您无法控制将在其中使用它的环境),那么最好考虑到它将在5.3中运行,并启用魔术引号的可能性。如果这是一个内部应用程序,并且您可以控制环境,并且您知道魔法引号被禁用,那么就没有必要检查它们