PHP anti-sql injection program code_PHP tutorial

PHP中文网
Release: 2023-02-28 18:54:01
Original
1127 people have browsed it

Put it into a common call file (such as the conn database link file) and filter all GET or POST data with special strings to achieve simple and effective SQL injection filtering. PHP beginners, welcome criticism and advice. Thank you!

  1. [Code] Simple function plus judgment

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");
}
Copy after login

2. [Code] (Updated on December 23, 2013) Combined What do you think of everyone’s advice being changed to this? Thank you all for your continued criticism and advice! (not case sensitive)

Function inject_check($sql_str) {
    return preg_match('/select|insert|and|or|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile/i', $sql_str);
}
if (inject_check($_SERVER['QUERY_STRING'])==1 or inject_check(file_get_contents("php://input"))==1){
    //echo "警告 非法访问!";
    header("Location: Error.php");
    exit;
}
Copy after login


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