小编use*_*304的帖子

是使用htmlspecialchars()进行输入/输出HTML清理,对于MySQL数据库糟糕的设计?

可能重复:
什么是最好的PHP输入清理功能?

是使用htmlspecialchars()进行输入/输出HTML清理,对于MySQL数据库糟糕的设计?

你是否应该只是不允许这些"危险"标志,因为它仍会显示b标签,i-tag和其他?怎么这样?

我问,因为它在wiki http://en.wikipedia.org/wiki/HTML_sanitization上

"通过清理用户提交的任何HTML代码,可以使用HTML清理来防止跨站点脚本和SQL注入攻击."

因此,除了使用PDO预处理语句,为了防止SQL注入,我想对所有输入和输出使用这个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();
Run Code Online (Sandbox Code Playgroud)

html php database

9
推荐指数
2
解决办法
6819
查看次数

标签 统计

database ×1

html ×1

php ×1