/** * 人格测验入口(支持代理配置动态化) */ require_once __DIR__ . '/includes/init.php'; // 检测代理分站上下文 $currentAgent = getCurrentAgent(); if (!$currentAgent && !empty($_SESSION['site_agent'])) { $currentAgent = $_SESSION['site_agent']; } // 子域名直接访问时不使用 /site/ 前缀 $requestHost = $_SERVER['HTTP_X_ORIGINAL_HOST'] ?? $_SERVER['HTTP_HOST'] ?? ''; $requestHost = explode(':', $requestHost)[0]; $hostParts = explode('.', $requestHost); $isAgentSubdomain = ( count($hostParts) >= 3 && !in_array($hostParts[0], ['www', 'admin', ''], true) && !filter_var($requestHost, FILTER_VALIDATE_IP) ); $sitePrefix = (!$isAgentSubdomain && $currentAgent && !empty($currentAgent['subdomain'])) ? '/site/' . $currentAgent['subdomain'] : ''; $siteTitle = $currentAgent ? htmlspecialchars($currentAgent['site_title'] ?: '2026年士兵职业基本适应性模拟检测系统') : '2026年士兵职业基本适应性模拟检测系统'; $footerCopyright = $currentAgent ? htmlspecialchars($currentAgent['footer_copyright'] ?? '') : ''; $footerTitle = $currentAgent ? htmlspecialchars($currentAgent['footer_title'] ?? '') : ''; // 读取静态模板 $htmlFile = __DIR__ . '/index.html'; if (!file_exists($htmlFile)) { http_response_code(500); echo '测试页面模板丢失'; exit; } $html = file_get_contents($htmlFile); if ($html === false) { http_response_code(500); echo '无法加载测试页面'; exit; } // 替换标题 $html = str_replace( '
© 2026 0x21c.cc · 博客:
', '' . $footerHtml . '
', $html ); // 替换注册/登录链接为代理前缀路径(兼容主站和代理站点) if ($sitePrefix) { $html = str_replace('href="/register.php"', 'href="' . $sitePrefix . '/register.php"', $html); $html = str_replace('href="/login.php"', 'href="' . $sitePrefix . '/login.php"', $html); $html = str_replace('href="/home.php"', 'href="' . $sitePrefix . '/home.php"', $html); } // 兼容:非子域名访问且当前不是 /site/ 路由时,使用 session 中的 site_prefix if (empty($sitePrefix) && !$isAgentSubdomain && !empty($_SESSION['site_prefix']) && strpos($_SERVER['REQUEST_URI'] ?? '', '/site/') === false) { $sitePrefix = $_SESSION['site_prefix']; } // 添加版本号到CSS/JS引用,解决缓存问题 $version = APP_VERSION; $html = preg_replace('/(href|src)=(["\'])([^"\']+\.(css|js))\2/i', '$1=$2$3?v=' . $version . '$2', $html); // 添加缓存控制meta(确保不缓存动态页面) $cacheMeta = '' . PHP_EOL; $cacheMeta .= ' ' . PHP_EOL; $cacheMeta .= ' '; $html = str_replace( '', $cacheMeta, $html ); // 插入公告弹窗 $annModalHtml = ''; if (!empty($announcement) || !empty($mainAnnouncements)) { $annHash = md5(($announcement ?? '') . json_encode($mainAnnouncements ?? [])); $agentAnnTitle = htmlspecialchars($currentAgent['site_title'] ?? '站点公告', ENT_QUOTES | ENT_HTML5, 'UTF-8'); $annModalHtml .= ''; $annModalHtml .= ''; } if ($annModalHtml) { $html = str_replace('