我一直用我的网站上这段代码很长一段时间,而只是想确保我正确sanatizing我的PHP $_POST
输入...
foreach($_POST as $key=>$val) //this code will sanitize your inputs.
$_POST[$key] = mysqli_real_escape_string($connection, $val);
说,例如我有岗位价值$_POST['comment']
那我想添加到数据库中,这是否是在数据库输入之前将其进行sanatize的好方法?
foreach($_POST as $key=>$val) //this code will sanitize your inputs.
$_POST[$key] = mysqli_real_escape_string($connection, $val);
//is this safe? or is there another step?
$comment = $_POST['comment'];
if($comment != ""){
//add $comment to database
}
有什么事,我还需要添加$comment
到MySQL数据库之前做?或者那些最上面的两行自己做魔术?请让我知道这是否是一种安全的方法,或者如果有更好的方法!谢谢!
用户编写查询,用户输入更安全的处理 – samayo
一定要使用的方法制得的语句(http://stackoverflow.com/a/60496) – HamZa