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!
[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"); }
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; }