我正在使用CURL檢查是否存在URL(HEAD請求),但是當我使用www.google.com
進行測試時,它會將我重定向到www.google.co.uk
- 可能是因爲我的服務器是基於英國的。我如何CURL www.google.com - 它一直將我重定向到.co.uk
有沒有辦法阻止這種情況發生?我不想刪除CURLOPT_FOLLOWLOCATION
選項,因爲這對於301重定向等是有用的。
我的部分代碼如下;
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
$output = curl_exec($ch);
// get data
$data = curl_getinfo($ch);
$data['url']
包含www.google.co.uk
當我設置$url
爲www.google.com
@Webbo - 我知道你已經接受了蒂姆的回答,但是有辦法做到這一點(參見我的回答)。 –
謝謝,你每天都會學到一些東西! –
哇,這個網站很棒,謝謝大家! –