12-24 3,155 views
1.替换(移除)sql接受参数的特殊字符
//替换(移除)sql接受参数的特殊字符
function removeSQL($val){
$val=mysql_escape_string(trim($val));
$arr=array("'",";","=","*","delete","alter","select","and ","or ","update","unique","show","set ");
foreach ($arr as $v) {
$val=str_ireplace($v,"",$val);
}
return $val;
}
//sql注入
function inject_check($sql_str) {
return eregi('select|insert|and|or|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile', $sql_str);
}
//sql注入
function verify_id($id=null) {
if(!$id) {
exit('没有提交参数!');
} elseif(inject_check($id)) {
exit('提交的参数非法!');
} elseif(!is_numeric($id)) {
exit('提交的参数非法!');
}
$id = intval($id);
return $id;
}