This commit is contained in:
make
2025-06-02 16:42:16 +08:00
parent 83c3bd512c
commit fe1e2c04d8

View File

@@ -236,7 +236,6 @@ class SiteContext
} else { } else {
$strView = 'novel/getNovelInfo.html'; $strView = 'novel/getNovelInfo.html';
} }
} else { } else {
$strView = 'index/index.html'; $strView = 'index/index.html';
} }
@@ -516,7 +515,7 @@ class SiteContext
// 判断是否为爬虫 // 判断是否为爬虫
$arrVisitInfo['vil_is_spider'] = $this->isSpider($arrVisitInfo['vil_user_agent']); $arrVisitInfo['vil_is_spider'] = $this->isSpider($arrVisitInfo['vil_user_agent']);
$strIp = $this->Request->ip(); $strIp = $this->getRealClientIp();
$strKeyLimit10 = 'access:' . $strIp; $strKeyLimit10 = 'access:' . $strIp;
$strKeyLimit100 = 'access100:' . $strIp; $strKeyLimit100 = 'access100:' . $strIp;
$strKeyBlacklist = 'blacklist:ips'; // 黑名单缓存键 $strKeyBlacklist = 'blacklist:ips'; // 黑名单缓存键
@@ -562,7 +561,6 @@ class SiteContext
throw new HttpException(404, 'Too Many Requests100'); throw new HttpException(404, 'Too Many Requests100');
//abort(403, 'Too Many Requests100'); //abort(403, 'Too Many Requests100');
} }
} }
/** /**
@@ -599,4 +597,24 @@ class SiteContext
return false; return false;
} }
/**
* 获取真实ip
*
* @return void
*/
protected function getRealClientIp()
{
$headers = $this->Request->header();
if (isset($headers['x-forwarded-for'])) {
$ips = explode(',', $headers['x-forwarded-for']);
return trim($ips[0]); // 取第一个(用户 IP
}
if (isset($headers['x-real-ip'])) {
return $headers['x-real-ip'];
}
return $this->Request->ip(); // 备用
}
} }