我主要想防止黑客通过发送消息和选择用户名字段通过脚本编写。
function protect($v) {
$v = mysql_real_escape_string($v);
$v = htmlentities($v, ENT_QUOTES);
$v = stripslashes($v);
$v = trim($v);
return $v;
}
上述php函数是否足够?我不需要超高安全性的东西,只要做好所有基本的就行了。
基本安全:
mysql_real_escape_string EVERYTHING当你做一个SQL查询,htmlentities当你想从数据库回显一些东西。
的例子:
<?php
$sql = "
SELECT
*
FROM
table
WHERE
id = '". mysql_real_escape_string($_GET['id']) ."'
LIMIT 1
"; // above this is the first security
$mysql = mysql_query($sql);
if($mysql){
$result = mysql_fetch_assoc($mysql);
echo htmlentities($result); // And here the second
}
?>
开始使用PDO。