简体   繁体   English

PHP获取最终重定向网址

[英]PHP get final redirect url

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

I tried the answers from other stackoverflow answers which works for other websites but not for the above link. 我尝试了其他stackoverflow答案的答案,这些答案适用于其他网站,但不适用于上述链接。 please help. 请帮忙。

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: 对于此特定站点,重定向是通过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