Home > Backend Development > PHP Tutorial > php防止sql注入代码实例_PHP

php防止sql注入代码实例_PHP

WBOY
Release: 2016-06-01 11:57:58
Original
886 people have browsed it

放到公用调用文件(如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");
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template