From 5d211fe39a526ce6f9ff7ba66e6bda9a9e072e77 Mon Sep 17 00:00:00 2001 From: Alone <675061370@qq.com> Date: Sat, 9 Nov 2024 11:52:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A6=81=E6=AD=A2=E7=88=AC=E8=99=AB=E5=85=A8?= =?UTF-8?q?=E7=BD=91=E6=90=9C=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/Tool.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/api/controller/Tool.php b/app/api/controller/Tool.php index eefa79f..71e37e9 100644 --- a/app/api/controller/Tool.php +++ b/app/api/controller/Tool.php @@ -159,6 +159,16 @@ class Tool extends QfShop $title = input('title'); $list = []; + + $userAgent = Request::header('user-agent'); + // 定义常见爬虫的 User-Agent 关键字 + $bots = ['Googlebot', 'Bingbot', 'Baiduspider']; + foreach ($bots as $bot) { + if (strpos($userAgent, $bot) !== false) { + return jerr('该接口禁止爬虫访问'); + } + } + if (empty($title)) { return jok('临时资源获取成功', $list); }