繁体   English   中英

PHP获取最终重定向网址

[英]PHP get final redirect url

我想从以下网址获得最终的重定向网址: http : //thatsthem.com/searching?ff=true&q0=Rob+Stott实际重定向到此网址: http : //thatsthem.com/search/Rob-Stott/325712f7

我尝试了其他stackoverflow答案的答案,这些答案适用于其他网站,但不适用于上述链接。 请帮忙。

对于此特定站点,重定向是通过JavaScript使用window.location.replace()因此您需要查看响应的正文:

$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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM