如果您设置卷曲选项CURLOPT_FOLLOWLOCATION,cURL将跟随您的位置重定向.
如果要获取标题,请将选项CURLOPT_HEADER设置为1,并从curl_exec()返回的HTTP响应将包含标题.你可以解析他们的位置.
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1); // return HTTP headers with response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return the response rather than output it
$resp = curl_exec($ch);
list($headers, $response) = explode("\r\n\r\n", $resp, 2);
// $headers now has a string of the HTTP headers
// $response is the body of the HTTP response
$headers = explode("\n", $headers);
foreach($headers as $header) {
if (stripos($header, 'Location:') !== false) {
echo "The location header is: '$header'";
}
}