php 批量过滤post,get敏感数据

//echo '<pre>';

//php 批量过滤post,get敏感数据

if (get_magic_quotes_gpc()) {
	$_GET = stripslashes_array($_GET,'GET');
	$_POST = stripslashes_array($_POST,'POST');
//	var_dump($_GET);die;
}

function stripslashes_array(&$array ,$leixing) {
	while(list($key,$var) = each($array)) {
		if ($key != 'argc' && $key != 'argv' && (strtoupper($key) != $key || ''.intval($key) == "$key")) {
			if (is_string($var)) {
				$v = lib_replace_end_tag(stripslashes($var),$leixing);
				$array[$key] = $v ;
			}
			if (is_array($var))  {
				$v = lib_replace_end_tag(stripslashes_array($var),$leixing);
				$array[$key] = $v;
			}
		}
	}
	return $array;
}


//PHP整站防注入程序,需要在公共文件中require_once本文件
//判断magic_quotes_gpc状态
if (@get_magic_quotes_gpc ()) {
	$_GET = sec ( $_GET );
	$_POST = sec ( $_POST );
	$_COOKIE = sec ( $_COOKIE );
	$_FILES = sec ( $_FILES );
}
$_SERVER = sec ( $_SERVER );
function sec(&$array) {
	//如果是数组,遍历数组,递归调用
	if (is_array ( $array )) {
		foreach ( $array as $k => $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 lib_replace_end_tag($str,$leixing)
{

//var_dump($str);
	if (empty($str)) return false;

	$str = htmlspecialchars($str);

	$str = filter_var($str, FILTER_SANITIZE_STRING);
//	$str = preg_replace('/[^a-zA-Z0-9]/', '', $str);
	$str = preg_replace('/[^\x7f-\xffa-zA-Z0-9]/', '', $str);//过滤除字母数字汉字 之外字符

	$str = str_replace( '=', "", $str);

	$str = str_replace( '/', "", $str);

	$str = str_replace("", "", $str);

	$str = str_replace(">", "", $str);

	$str = str_replace("<", "", $str);

	$str = str_replace("<SCRIPT>", "", $str);

	$str = str_replace("</SCRIPT>", "", $str);

	$str = str_replace("<script>", "", $str);

	$str = str_replace("</script>", "", $str);

	$str=str_replace("select","",$str);

	$str=str_replace("join","",$str);

	$str=str_replace("union","",$str);

	$str=str_replace("where","",$str);

	$str=str_replace("insert","",$str);

	$str=str_replace("delete","",$str);

	$str=str_replace("update","",$str);

	$str=str_replace("like","",$str);

	$str=str_replace("drop","",$str);

	$str=str_replace("create","",$str);

	$str=str_replace("modify","",$str);

	$str=str_replace("rename","",$str);

	$str=str_replace("alter","",$str);

	$str=str_replace("cas","",$str);

	$str=str_replace("&","&",$str);

	$str=str_replace(">",">",$str);

	$str=str_replace("<","<",$str);

	$str=str_replace(" ",chr(32),$str);

	$str=str_replace(" ",chr(9),$str);

	$str=str_replace(" ",chr(9),$str);

	$str=str_replace("&",chr(34),$str);

	$str=str_replace("'",chr(39),$str);

	$str=str_replace("<br />",chr(13),$str);

	$str=str_replace("''","'",$str);

	$str=str_replace("css","'",$str);

	$str=str_replace("CSS","'",$str);

	return $str;

}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值