<?php
$target = 'http://daigua.qq68447.top';
$url = $target . $_SERVER['REQUEST_URI'];

// 1. 强制设置 Header，防止变成下载
header('Content-Type: text/html; charset=utf-8');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// ... 其他 curl 设置保持不变 ...


// 2. 获取当前请求的路径和参数
$url = $target . $_SERVER['REQUEST_URI'];

// 3. 初始化 cURL 抓取网页
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // 自动跟随重定向
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HEADER, false);

// 关键：模拟原站 Host，防止被目标服务器拒绝
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Host: daigua.qq68447.top',
    'Accept-Encoding: identity' // 强制不压缩，方便替换文字
]);

// 4. 执行抓取
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

// 如果抓取失败（比如 404 或 500）
if ($httpCode !== 200 && empty($response)) {
    die("无法连接到目标站点，请检查服务器网络或目标站状态。代码: " . $httpCode);
}

// 5. --- 重点：内容替换逻辑 ---

// A. 替换联系方式（文字）
$response = str_replace('68447', '10500346', $response);

// B. 替换跳转链接（比如 QQ 交谈链接）
$response = str_replace('uin=68447', 'uin=你的QQ号', $response);

// C. 修复路径问题（如果样式乱了，就把相对路径改为绝对路径）
// 这一步是将原站所有的 href="/" 或 src="/" 补全成对方的域名地址
$response = str_replace('href="/', 'href="' . $target . '/', $response);
$response = str_replace('src="/', 'src="' . $target . '/', $response);

// D. 隐藏原站域名（防止用户点击某些地方跳回原站）
$response = str_replace('daigua.qq68447.top', $_SERVER['HTTP_HOST'], $response);

// 6. 输出最终修改后的内容
echo $response;
