当前位置:首页 > PHP教程 > PHP常见问题

php防止sql注入代码实例

放到公用调用文件(如conn数据库链接文件),对所有get或post的数据进行过滤特殊字符串,以实现简单有效的sql注入过滤

复制代码 代码如下:

function inject_check($sql_str) {
 return eregi('select|insert|and|or|update|delete|'|/*|*|../|./|union|into|load_file|outfile', $sql_str);
}
if (inject_check($_server['query_string'])==1 or inject_check(file_get_contents("php://input"))==1){
 //echo "警告 非法访问!";
 header("location: error.php");
}


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!