1.小说搜索重定向首页
2.伪造小说恢复修改前,直接使用小说详情同一个html 3.限制伪造谷歌爬虫ua
This commit is contained in:
@@ -505,14 +505,7 @@ class SiteContext
|
||||
{
|
||||
|
||||
$arrVisitInfo = [
|
||||
//'vil_ip' => $this->Request->ip(),
|
||||
'vil_user_agent' => $this->Request->server('HTTP_USER_AGENT'),
|
||||
// 'vil_url' => $this->Request->url(true),
|
||||
// 'vil_method' => $this->Request->method(),
|
||||
// 'vil_headers' => json_encode($this->Request->header()), // 保存所有 HTTP 头信息
|
||||
// 'vil_timestamp' => date('Y-m-d H:i:s'), // 获取当前时间
|
||||
// 'vil_content_type' => 'page',
|
||||
// 'vil_content_id' => $this->Request->url(true),
|
||||
];
|
||||
|
||||
// 判断是否为爬虫
|
||||
@@ -538,7 +531,6 @@ class SiteContext
|
||||
Cache::store('redis')->handler()->expire($strKeyLimit100, 60 * 10); // 设置 10分钟 过期
|
||||
}
|
||||
|
||||
// var_dump($intRequestTotalLimit10);
|
||||
// 检查请求次数是否超过限制
|
||||
if ($intRequestTotalLimit10 > 60 && !$arrVisitInfo['vil_is_spider']) {
|
||||
throw new HttpException(404, 'Too Many Requests');
|
||||
@@ -555,14 +547,30 @@ class SiteContext
|
||||
//abort(403, 'Too Many Requests100');
|
||||
}
|
||||
|
||||
$strAGEN = 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Amazonbot/0.1; +https://developer.amazon.com/support/amazonbot) Chrome/119.0.6045.214 Safari/537.36';
|
||||
if ($arrVisitInfo['vil_user_agent'] == $strAGEN) {
|
||||
throw new HttpException(404, 'Too Many Requests100');
|
||||
//abort(403, 'Too Many Requests100');
|
||||
/**
|
||||
* 不会拦掉真的 Googlebot(因为真的只会是 Chrome/41.0 固定 UA)。
|
||||
* 但是 如果你要更精准一点,可以只拦截 Googlebot + Chrome 但不是 Chrome/41
|
||||
*/
|
||||
if (stripos($arrVisitInfo['vil_user_agent'], 'Googlebot/2.1') !== false
|
||||
&& stripos($arrVisitInfo['vil_user_agent'], 'Chrome/') !== false
|
||||
&& stripos($arrVisitInfo['vil_user_agent'], 'Chrome/41.0.2272.96') === false) {
|
||||
throw new HttpException(403, 'HTTP/1.1 403 Forbidden');
|
||||
}
|
||||
if (preg_match('/Chrome\/119\.0\.6045\.214/', $arrVisitInfo['vil_user_agent'])) {
|
||||
throw new HttpException(404, 'Too Many Requests100');
|
||||
//abort(403, 'Too Many Requests100');
|
||||
|
||||
// 定义需要屏蔽的 UA 关键字 / 正则
|
||||
$arrDenyUserAgents = [
|
||||
'Amazonbot', // 屏蔽 Amazon 爬虫
|
||||
'zgrab', // 安全扫描工具
|
||||
'crawler', // 明示 crawler
|
||||
'Chrome\/119\.0\.6045\.214', // 特定版本号 UA
|
||||
];
|
||||
|
||||
// 遍历检查 UA
|
||||
foreach ($arrDenyUserAgents as $strPattern) {
|
||||
if (preg_match("/$strPattern/i", $arrVisitInfo['vil_user_agent'])) {
|
||||
throw new HttpException(404, 'Too Many Requests100');
|
||||
// 或者用 abort(403, 'Too Many Requests100');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -577,8 +585,8 @@ class SiteContext
|
||||
# ✅ 主流搜索引擎爬虫(按需维护)
|
||||
$arrSpiders = [
|
||||
'Baiduspider',
|
||||
'Googlebot',
|
||||
'Googlebot-Mobile',
|
||||
// 'Googlebot',
|
||||
// 'Googlebot-Mobile',
|
||||
'360Spider',
|
||||
'HaosouSpider',
|
||||
'Sogou',
|
||||
|
||||
Reference in New Issue
Block a user