我正在构建一个MVC应用程序来管理一个创造性的项目组合(把它放到git集线器上)。我需要一些东西来保护数据库连接,基本上我有一个类来管理所有的数据库事务。
我需要创建一个类,或者找到一个可以保护所有SQL查询免受XXS或SQL攻击的类。对于保护PHP数据库连接,您有什么建议?
发布于 2011-07-03 10:08:55
试着用这个函数过滤你的POST,GET请求
function protect($string)
{
if (ini_get('magic_quotes_gpc') == 'off') // check if magic_quotes_gpc is on and if not add slashes
{
$string = addslashes($string);
}
// move html tages from inputs
$string = htmlentities($string, ENT_QUOTES);
//removing most known vulnerable words
$codes = array("script","java","applet","iframe","meta","object","html", "<", ">", ";", "'","%");
$string = str_replace($codes,"",$string);
//return clean string
return $string;
}您可以使用array_map函数轻松地将其应用于整个输入
$input = array_map('protect','$_POST');
$input = array_map('protect','$_GET');发布于 2011-07-03 11:00:22
使用PDO的准备好的语句访问数据库可以使查询免受注入的影响。http://us2.php.net/manual/en/pdo.prepare.php
使用htmlspecialchars()可以使输出不受xxs的影响。http://us2.php.net/manual/en/function.htmlspecialchars.php
https://stackoverflow.com/questions/6560663
复制相似问题