PHP基本防SQL注入函数与安全过滤函数

来自:互联网
时间:2018-08-26
阅读:
function sql_check($Sql_Str) {//自动过滤Sql的注入语句。
    $check=preg_match('/select|insert|update|delete|'|\*|*|../|./|union|into|load_file|outfile/i',$Sql_Str);
    if ($check) {
        echo '<script language="JavaScript">alert("系统警告:nn请不要尝试在参数中包含非法字符尝试注入!");</script>';
        exit();
    }else{
        return $Sql_Str;
    }
}
function safe($s){ //安全过滤函数
    if(get_magic_quotes_gpc()){ $s=stripslashes($s); }
    $s=MySQL_real_escape_string($s);
    return $s;
}
返回顶部
顶部