一.form表单参数安全验证函数(防止sql注入等等)!
/** * 表单参数安全判断,防止sql注入:方法一(推荐) * author: xiaochuan * @param: mixed $value 参数值 * @param: array $rules 检测规则 * return: boolean */ function check_param($value, $rules=''){ $rules = empty($rules) ? [1,2] : $rules; // 检测规则 static $chars = [ 1 => "select|delete|update|insert|union|into|load_file|outfile", 2 => "\'|\*|\\|\\$|\.\/", 3 => "\'|\/|\*|\\|\\$|\.\/", 4 => "\.", ]; $needChars = []; foreach($rules as $one){ if(isset($chars[$one])) $needChars[] = $chars[$one]; } if(!empty($needChars)){ if(is_array($value)){ foreach($value as $val){ $res = check_param($val,$rules); if(!$res){ return false; } } }else{ if(preg_match("/".implode("|",$needChars)."/i",$value)){ return false; } } } return true; }
转载请注明来源地址:小川编程 » https://www.youhutong.com/index.php/article/index/40.html