当HTTP状态代码为302时,如何使用cURL获取目标URL?
<?PHP
$url = "http://www.ecs.soton.ac.uk/news/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec($ch);
$status_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
if($status_code=302 or $status_code=301){
$url = "";
// I want to to get the destination url
}
curl_close($ch);
?>
Run Code Online (Sandbox Code Playgroud) 我知道当我将CURLOPT_FOLLOWLOCATION设置为true时,cURL将跟随Location标头并重定向到新页面.但是有可能只获得新页面的标题而不实际重定向吗?还是不可能?