您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP防注入漏洞攻击的过滤函数代码

2024/3/7 0:58:34发布24次查看
php整站防注入程序,需要在公共文件中require_once本文件,因为现在网站被注入攻击现象很严重,所以推荐大家使用,具体见如下代码。
$v ) {
$array [$k] = sec ( $v );
}
} else if (is_string ( $array )) {
//使用addslashes函数来处理
$array = addslashes ( $array );
} else if (is_numeric ( $array )) {
$array = intval ( $array );
}
return $array;
}
//整型过滤函数
function num_check($id) {
if (! $id) {
die ( '参数不能为空!' );
} //是否为空的判断
else if (inject_check ( $id )) {
die ( '非法参数' );
} //注入判断
else if (! is_numetic ( $id )) {
die ( '非法参数' );
}
//数字判断
$id = intval ( $id );
//整型化
return $id;
}
//字符过滤函数
function str_check($str) {
if (inject_check ( $str )) {
die ( '非法参数' );
}
//注入判断
$str = htmlspecialchars ( $str );
//转换html
return $str;
}
function search_check($str) {
$str = str_replace ( _, \_, $str );
//把_过滤掉
$str = str_replace ( %, \%, $str );
//把%过滤掉
$str = htmlspecialchars ( $str );
//转换html
return $str;
}
//表单过滤函数
function post_check($str, $min, $max) {
if (isset ( $min ) && strlen ( $str ) $max) {
die ( '最多$max字节' );
}
return stripslashes_array ( $str );
}
//防注入函数
function inject_check($sql_str) {
return eregi ( 'select|inert|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile', $sql_str );
// www.scutephp.com 进行过滤,防注入
}
function stripslashes_array(&$array) {
if (is_array ( $array )) {
foreach ( $array as $k => $v ) {
$array [$k] = stripslashes_array ( $v );
}
} else if (is_string ( $array )) {
$array = stripslashes ( $array );
}
return $array;
}
?>
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product