sql generic anti-injection system This article provides anti-sql injection code is a php tutorial sql double filter illegal characters function, he can be based on user-defensive SQL injection Oh, first filter some sql command, then the post get filtered once, the best validation. * / // anti-injection
$ arrfiltrate = array (update, delete, selert, drop, exec, cast, union, union); // jump after the error url, do not fill the default previous page $ strgourl = ""; // Whether there is an array value function funstringexist ($ strfiltrate, $ arrfiltrate) { foreach ($ arrfiltrate as $ key => $ value) { if (eregi ($ value, $ strfiltrate)) { return true; } } return false; } // Combine $ _post and $ _get if (function_exists (array_merge)) { $ arrpostandget = array_merge ($ http_post_vars, $ http_get_vars); } else { foreach ($ http_post_vars as $ key => $ value) { $ arrpostandget [] = $ value; } foreach ($ http_get_vars as $ key => $ value) { $ arrpostandget [] = $ value; } } // validation begins foreach ($ arrpostandget as $ key => $ value) { if (funstringexist ($ value, $ arrfiltrate)) { echo ""; if (empty ($ strgourl)) { echo ""; } else { echo ""; } echo "<script> alert ('system detected an illegal character!'); history.back (); </ script>"; exit (); } } ?>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.