PHP采用301跳转方式防CC拦截

PHP采用301跳转方式防CC拦截 降低CC攻击的效果

<?php
empty( $_SERVER[ 'HTTP_VIA' ] )or exit( 'Access Denied' );
$seconds = 10; //时间段[秒]
$refresh = 5; //刷新次数
//设置监控变量
$cur_time = time();
if ( isset( $_SESSION[ 'last_time' ] ) ) {
	$_SESSION[ 'refresh_times' ] += 1;
} else {
	$_SESSION[ 'refresh_times' ] = 1;
	$_SESSION[ 'last_time' ] = $cur_time;
}
//处理监控结果
if ( $cur_time - $_SESSION[ 'last_time' ] < $seconds ) {
	if ( $_SESSION[ 'refresh_times' ] >= $refresh ) {
		//跳转验证
		$url = 'http://' . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ];
		$msg = mb_convert_encoding( "<title>安全检查</title><h3>检测到CC攻击,正在进行浏览器安全检查!</h3>", "UTF-8", "GBK" );
		exit( $msg . "<meta http-equiv='refresh' content='5;url={$url}'>" ); //5是定时跳转的时间,后期可以根据时间段调整跳转时间
	}
} else {
	$_SESSION[ 'refresh_times' ] = 0;
	$_SESSION[ 'last_time' ] = $cur_time;
}
?>

给TA打赏
共{{data.count}}人
人已打赏
PHP技术

一个中高级PHP工程师所应该具备的能力

2018-7-2 10:53:16

PHP技术

ProRank 您的网站全能分析专家

2018-7-7 12:20:11

    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索