如果對方網站通過判斷 User-Agent 頭信息來判斷你的瀏覽器類型,你可以嘗試修改 User-Agent 頭信息來模擬其他瀏覽器的訪問,以繞過對方網站的檢測。在 PHP 中,你可以使用 cURL 庫來發送 HTTP 請求,並設置 User-Agent 頭信息。
以下是一個示例代碼:
// 設置目標 URL
$url = 'https://example.com';
// 初始化 cURL
$ch = curl_init();
// 設置 cURL 選項
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 設置 User-Agent 頭信息
$user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36';
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
// 發送 HTTP 請求
$response = curl_exec($ch);
// 關閉 cURL
curl_close($ch);
// 處理響應結果
if ($response === false) {
echo '請求失敗';
} else {
echo $response;
}在上述代碼中,我們使用了 Chrome 瀏覽器的 User-Agent 頭信息來模擬瀏覽器訪問。你可以根據實際情況選擇其他瀏覽器的 User-Agent 頭信息。