您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP简单代码防止SQL注入

2024/11/3 9:34:27发布42次查看
放到公用调用文件(如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);}
复制代码
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;}
复制代码
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product