可能重复:
防止PHP 中SQL注入的最佳方法
由于我使用的是mysql_real_eescape_string和strip_tag,所以这段代码安全吗是否需要更改为pdo?我无法将以下代码转换为pdo,因为它的显示无法修改标题。
<?php
include('config.php');
$link =mysql_connect($db_host,$username,$password);
mysql_select_db($db_name);
$id= $_POST["uniqi"];
$comments= $_POST["comments"];
$comments= mysql_real_escape_string($comments);
$comments = strip_tags($comments);
$update = "UPDATE mastertable SET comments = '$comments' WHERE id_pk= '$id'";
mysql_query($update, $link);
mysql_close();
header('Location: http://www.xxxx.com/xxxxx/xxxx.php?cntmsg=Comment Updated');
?>
这不是安全的代码-您的代码不处理$id
变量。
$id= $_POST["uniqi"];
$id= mysql_real_escape_string($id);
$id = strip_tags($id);