<分区>
Possible Duplicate:
What are the best PHP input sanitizing functions?
是否使用 htmlspecialchars() 进行输入/输出 HTML 清理,因为 MySQL 数据库设计不当?
您是否应该只是不允许这些“危险”标志,因为它仍然会显示 b-tags、i-tags 和其他?以及如何做到这一点?
我问是因为它在 wiki 上说 http://en.wikipedia.org/wiki/HTML_sanitization
“HTML 清理可用于通过清理用户提交的任何 HTML 代码来防止跨站点脚本和 SQL 注入(inject)攻击。”
因此,除了使用 PDO 准备语句之外,为了防止 SQL 注入(inject),我想将此 htmlspecialchars 用于所有输入和输出。但也许我应该使用其他东西?
例如,这是执行插入语句的好方法吗?
$type= htmlspecialchars($_POST['animaltype']);
$name= htmlspecialchars($_POST['animalname']);
$age= htmlspecialchars($_POST['animalage']);
$descr= htmlspecialchars($_POST['animaldescription']);
$foto= htmlspecialchars($_POST['animalfotourl']);
$date=htmlspecialchars($_POST['animalhomelessdate']);
$sqlquery = "INSERT INTO animals_tbl(animaltype, animalname, animalage, animaldescription, animalfotourl, animalhomelesssince) VALUES (':type',':name',':age',':descr', ':foto', ':date')";
$stmt = $conn->prepare($sqlquery);
$stmt->bindParam(':type',$type, PDO::PARAM_STR);
$stmt->bindParam(':name',$name, PDO::PARAM_STR);
$stmt->bindParam(':age',$age, PDO::PARAM_INT);
$stmt->bindParam(':descr',$descr, PDO::PARAM_STR);
$stmt->bindParam(':foto',$foto, PDO::PARAM_STR);
$stmt->bindParam(':date',$date, PDO::PARAM_STR);
$stmt->execute();