当我使用 curl 获取重定向网址时,标题函数不会重定向


Header function won't redirect, when i use curl to get redirect url

>问题在代码中得到了更好的说明:

<?php
$ch = curl_init();
$url = 'http://google.com';
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
$result_header = curl_getinfo($ch);
curl_close($ch);
header('Location '.$result_header['redirect_uri']);//Here regional version of google, in my case its http://google.ru. 
?>

所以标题不起作用。如何解决这个问题?谢谢。最好的问候阿尔比娜。

代码中实际上有两个错误:

  • 它应该是redirect_url的,带有l,而不是i
  • 缺少标头名称后的冒号

更正它应该是

header('Location: '.$result_header['redirect_url']);