放到公用调用文件(如conn数据库链接文件),对所有get或post的数据进行过滤特殊字符串,以实现简单有效的sql注入过滤。php初学者,欢迎批评指点 谢谢!
[代码]简单函数加判断
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. [代码](2013年12月23日更新)结合了大家的指点 改成这样 大家觉得如何?感谢大家继续批评指教!(不区分大小写的)
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;
}
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号