PHP代码如何放行代理服务器IP
//代理IP直接退出empty($_SERVER['HTTP_VIA'])orexit('AccessDenied');//防止快速刷新session_start();$...
//代理IP直接退出
empty($_SERVER['HTTP_VIA']) or exit('Access Denied');
//防止快速刷新
session_start();
$seconds = '3'; //时间段[秒]
$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){
//跳转至攻击者服务器地址
header(sprintf('Location:%s', 'http://127.0.0.1'));
exit('Access Denied');
}
}else{
$_SESSION['refresh_times'] = 0;
$_SESSION['last_time'] = $cur_time;
}
以上PHP代码是让所有代理IP都拒绝访问,请PHP大神帮忙修改为,放行某个或者多个代理IP访问。 展开
empty($_SERVER['HTTP_VIA']) or exit('Access Denied');
//防止快速刷新
session_start();
$seconds = '3'; //时间段[秒]
$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){
//跳转至攻击者服务器地址
header(sprintf('Location:%s', 'http://127.0.0.1'));
exit('Access Denied');
}
}else{
$_SESSION['refresh_times'] = 0;
$_SESSION['last_time'] = $cur_time;
}
以上PHP代码是让所有代理IP都拒绝访问,请PHP大神帮忙修改为,放行某个或者多个代理IP访问。 展开
1个回答
展开全部
<?php
//授权 IP
$ips = ['119.29.29.29', '8.8.8.8'];
//代理IP直接退出
empty($_SERVER['HTTP_VIA']) or exit('Access Denied');
//防止快速刷新
session_start();
$seconds = '3'; //时间段[秒]
$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 && ! in_array($getIP, $ips)) {
//跳转至攻击者服务器地址
header(sprintf('Location:%s', '
));
exit('Access Denied');
}
} else {
$_SESSION['refresh_times'] = 0;
$_SESSION['last_time'] = $cur_time;
}
function getIP() {
if (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
} elseif (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('HTTP_X_FORWARDED')) {
$ip = getenv('HTTP_X_FORWARDED');
} elseif (getenv('HTTP_FORWARDED_FOR')) {
$ip = getenv('HTTP_FORWARDED_FOR');
} elseif (getenv('HTTP_FORWARDED')) {
$ip = getenv('HTTP_FORWARDED');
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
Storm代理
2023-08-29 广告
2023-08-29 广告
"StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,I...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |