//防止SQL注入 function check_sql($str){ $str = str_replace("'","",$str); $str = str_replace(" or ","",$str); $str = str_replace(" and ","",$str); $str = str_replace(" select ","",$str); $str = str_replace(" update ","",$str); $str = str_replace(" delete ","",$str); $str = str_replace('"','',$str); return $str; } //检查身份证 function check_idcard($idcard){ if(strlen($idcard)!=18){ return false; } //只能是18位 $idcard_base = substr($idcard, 0, 17); //取出本体码 $verify_code = substr($idcard, 17, 1); //取出校验码 $factor = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); //加权因子 $verify_code_list = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); //校验码对应值 //根据前17位计算校验码 $total = 0; for($i=0; $i<17; $i++){ $total += substr($idcard_base, $i, 1)*$factor[$i]; } $mod = $total % 11; //取模 //比较校验码 if($verify_code == $verify_code_list[$mod]){ return true; }else{ return false; } } //检查手机号 function check_tel($tel){ $search = '/^0?1[3|4|5|6|7|8|9][0-9]\d{8}$/'; if(preg_match($search, $tel)){ return true; }else{ return false; } }