将CURLOPT_FOLLOWLOCATION设置为TRUE。
$opts = array(CURLOPT_RETURNTRANSFER => true, // do not output to browser
CURLOPT_URL => $url, // set URL
CURLOPT_NOBODY => true, // do a HEAD request only
CURLOPT_FOLLOWLOCATION => true // follow location headers
CURLOPT_TIMEOUT => $timeout); // set timeout如果您不必卷曲,您也可以使用标准的PHP http包装器(这可能甚至在内部卷曲)。示例代码:
$url = 'http://example.com/';
$code = FALSE;
$options['http'] = array(
'method' => "HEAD"
);
$context = stream_context_create($options);
$body = file_get_contents($url, NULL, $context);
foreach($http_response_header as $header)
{
sscanf($header, 'HTTP/%*d.%*d %d', $code);
}
echo "Status code (after all redirects): $code
\n";请参阅HEAD first with PHP Streams。
相关问题是How can one check to see if a remote file exists using PHP?。