我有防止sql注入的功能 是一个很好的功能,真正起到防止攻击的作用 开始显示字符问题
这个词是“ controledefinanças” 在var_dump中,我看到字符串(31)“ controle de finan& Atilde& sectas ”
我正在尝试一些方法并且失败2天请帮助我
function Anti_Sql_Injection($string){
if(ini_get('magic_quotes_gpc') == 'off'){
$string = addslashes($string);
}
$string = htmlentities($string, ENT_QUOTES);
$codes = array("script","java","applet","iframe","meta","object","html","CONCAT","CHAR","FLOOR","RAND", "<", ">", ";", "'","%");
$string = str_replace($codes,"",$string);
return $string;
}
答案 0 :(得分:1)
试试这个;
function Anti_Sql_Injection($string){
if(ini_get('magic_quotes_gpc') == 'off') {
$string = addslashes($string);
}
$string = htmlspecialchars($string, ENT_QUOTES,"UTF-8");
$codes = array("script","java","applet","iframe","meta","object","html","CONCAT","CHAR","FLOOR","RAND", "<", ">", ";", "'","%");
$string = str_replace($codes,"",$string);
return $string;
}
我还想告诉你PDO。它通过预处理语句内置SQL注入。查看this教程以开始使用PDO。我知道它有点陈旧,但仍然有效且解释清楚。
答案 1 :(得分:0)
为什么使用名为Anti_Sql_Injection()
的函数来阻止XSS攻击? You should be using Prepared Statements停止SQL注入以及相应的单独strategy for stopping XSS attacks。
autoescape
块(例如Twig)。htmlspecialchars($string, ENT_QUOTES | ENT_HTML5, 'UTF-8');
使用准备好的陈述。像EasyDB这样的库(包装PDO)可以减少迁移的痛苦。