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.com
@Webbo - 당신이 팀의 대답을 받아 들였다는 것을 알고 있지만 그것을 할 수있는 방법이 있습니다 (제 대답 참조). –
감사합니다, 당신은 매일 뭔가를 배웁니다! –
와우,이 사이트는 대단합니다, 모두에게 감사합니다! –