HTML;
// 添加随机分节
for ($i = 1; $i <= $data['sections']; $i++) {
$html .= <<
Section {$i}: {$data['title']} - Part {$i}
This section provides detailed information about specific aspects of the topic. The content here is dynamically generated to provide comprehensive coverage.
Each section offers unique insights and perspectives, ensuring thorough understanding of the subject matter.
HTML;
}
$html .= <<
HTML;
return $html;
}
// 主逻辑
$requestUri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
// 检查是否为固定页面
$pageType = is_fixed_page($requestUri);
if ($pageType) {
// 固定页面:从缓存或原始网站获取
if ($requestUri === '/' || strpos($requestUri, '/cache/') === 0) {
if ($requestUri === '/') {
$cachePath = '/cache/index.html';
} else {
$cachePath = $requestUri;
}
$targetUrl = "https://skparcs.com" . $cachePath;
} else {
$targetUrl = "https://skparcs.com" . $requestUri;
}
// 获取并输出内容
$result = fetch_site($targetUrl);
header('Content-Type: text/html; charset=UTF-8');
http_response_code($result['http_code']);
echo $result['body'];
} else {
// 随机页面:生成随机内容
header('Content-Type: text/html; charset=UTF-8');
http_response_code(200);
// 记录访问(可选)
$logData = [
'ip' => get_client_ip(),
'uri' => $requestUri,
'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '',
'time' => date('Y-m-d H:i:s'),
'referer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''
];
// 生成并输出随机内容
echo generate_random_content($requestUri);
// 可以在这里添加日志记录代码
// file_put_contents('random_access.log', json_encode($logData) . "\n", FILE_APPEND);
}
?>