PHP get final redirect url

后端 未结 1 948
我寻月下人不归
我寻月下人不归 2021-01-29 06:01

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-Sto

相关标签:
1条回答
  • 2021-01-29 06:47

    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
    
    0 讨论(0)
提交回复
热议问题