一.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
1、本站发布的内容仅限用于学习和研究目的.请勿用于商业或非法用途,下载后请24小时内删除。
2、本站所有内容均不能保证其完整性,不能接受请勿购买或下载,如需完整程序,请去其官方购买正版使用
3、本站联系方式Email:admin@youhutong.com ,收到邮件会第一时间处理。
4、如侵犯到任何版权问题,请立即告知本站(立即在线告知),本站将及时删除并致以最深的歉意

