簡體   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