简体   繁体   中英

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

I tried the answers from other stackoverflow answers which works for other websites but not for the above link. 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:

$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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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