PHP自定义函数(10)--- 防sql注入

2019-05-13T14:06:24
//sql注入
function inject_check($sql_str) { 
    return eregi('select|insert|and|or|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile', $sql_str);
} 
//sql注入
function verify_id($id=null) { 
    if(!$id) {
        exit('没有提交参数!'); 
    } elseif(inject_check($id)) { 
        exit('提交的参数非法!');
    } elseif(!is_numeric($id)) { 
        exit('提交的参数非法!'); 
    } 
    $id = intval($id); 
    return $id; 
}
//替换(移除)sql接受参数的特殊字符
function removeSQL($val){
    $val=mysql_escape_string(trim($val));
    $arr=array("'",";","=","*","delete","alter","select","and ","or ","update","unique","show","set ");
    foreach ($arr as $v) {
        $val=str_ireplace($v,"",$val); 
    }
    return $val;
}
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »