您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> php编程 >> 正文

php防止sql注入代码实例

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 本文介绍了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"); }