首页> 资讯> PHP基本防SQL注入函数与安全过滤函数

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

发布时间:2016-10-29 12:29:01来源:本站整理

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("系统警告:\n\n请不要尝试在参数中包含非法字符尝试注入!");</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;
}

举报