// 爬虫UA识别 $spiderUa = [ 'Baiduspider','Baiduspider-render','Baiduspider-image','Baiduspider-video', 'bingbot','Googlebot','Googlebot-Image','ByteSpider','SogouSpider', 'ToutiaoSpider','GPTBot','ClaudeBot','YandexBot','DuckDuckBot' ]; $ua = $_SERVER['HTTP_USER_AGENT'] ?? ''; $isSpider = false; foreach ($spiderUa as $bot) { if(stripos($ua, $bot) !== false){ $isSpider = true; define('SPIDER_VISIT', true); break; } } if(!$isSpider){ define('SPIDER_VISIT', false); } // 爬虫关闭SESSION相关Cookie配置 if($isSpider){ ini_set('session.use_cookies', 0); ini_set('session.auto_start', 0); ini_set('session.use_only_cookies', 0); ini_set('session.cookie_httponly',0); ini_set('output_buffering', 'On'); } // 隐藏PHP版本 ini_set('expose_php', 'Off'); header_remove('X-Powered-By'); // 爬虫不开启session,从源头减少Cookie if(!$isSpider){ session_start(); } define('IS_INDEX', true); define('URL_BIND', 'home'); // PHP版本检测 if (PHP_VERSION < '5.4') { header('Content-Type:text/html; charset=utf-8'); exit('PHP版本过低,需≥5.4'); } // 加载页面主体 ob_start(); require dirname(__FILE__) . '/core/start.php'; $html = ob_get_clean(); // ===================== 删除了下面4行清除统计JS的正则 ===================== // $html = preg_replace('~~is', '', $html); // $html = preg_replace('~~is', '', $html); // if($isSpider){ // $html = preg_replace('~]*visits.*?~is','',$html); // $html = preg_replace('~]*spider.*?~is','',$html); // } // 输出最终页面 echo $html;