php获取重定向url
我的原始链接php获取重定向url,php,curl,url-redirection,Php,Curl,Url Redirection,我的原始链接 function get_redirect_final_target($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // follow redirects curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // set referer on
function get_redirect_final_target($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // follow redirects
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // set referer on redirect
curl_exec($ch);
$target = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
if ($target)
return $target;
return false;
}
回显重定向的链接,但它将回显相同的链接,因为它无法检测到任何重定向头。但我的链接将有一个302重定向
$url = "http://www.mylink";
使用其他正常重定向链接将工作,但我的链接应该重定向,但它无法获得标题位置链接。
非常感谢您的帮助 只需使用get\u headers PHP函数,看看您得到的是200还是302。get\u redirect\u target是否正确应该是
get\u redirect\u final\u target
?使用curl\u error()
您会得到一个SSL错误我只是漏掉了一个字,但它也有同样的问题。您可以检查我的原始url,它将重定向到视频。但是脚本无法检测重定向。是SSL问题导致了问题吗?如何修复?在测试url的firefox addon http live标头中,原始url将找到http/2.0 302
,重定向的url将找到http/2.0 200 OK
,这是正常的。。每个重定向得到302,然后在最后一个真实页面上得到200。
echo get_redirect_final_target($url);