PHP获取最终重定向网址 [英] PHP get final redirect url
问题描述
我喜欢从这里获取最终的重定向网址: http:// thatsthem.com/searching?ff=true&q0=Rob+Stott ,其实际重定向到此: http://thatsthem.com/search/Rob-Stott/325712f7
I like to get the final redirect url from the this: http://thatsthem.com/searching?ff=true&q0=Rob+Stott which actually redirects to this: http://thatsthem.com/search/Rob-Stott/325712f7
我试过其他stackoverflow答案的答案,适用于其他网站,但不是上面的链接。请帮助。
I tried the answers from other stackoverflow answers which works for other websites but not for the above link. please help.
推荐答案
在此特定网站的情况下,重定向通过JavaScript与窗口.location.replace()
,因此您需要查看响应的正文:
In the case of this particular site, the redirection is done through JavaScript with window.location.replace()
so you'll need to look in the body of the response:
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($c, CURLOPT_URL, "http://thatsthem.com/searching?ff=true&q0=Rob+Stott");
$html = curl_exec($c);
$redirection_url = preg_match("/window\.location\.replace\('(.*?)'\)/", $html, $m) ? $m[1] : null;
echo $redirection_url; // http://thatsthem.com/search/Rob-Stott/325712f7
这篇关于PHP获取最终重定向网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!