【问题标题】:PHP get final redirect urlPHP 获取最终重定向 url
【发布时间】:2015-09-30 12:19:44
【问题描述】:

我喜欢从这个:http://thatsthem.com/searching?ff=true&q0=Rob+Stott 获取最终的重定向 url,它实际上重定向到这个:http://thatsthem.com/search/Rob-Stott/325712f7

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

【问题讨论】:

    标签: php redirect curl url-redirection


    【解决方案1】:

    在这个特定站点的情况下,重定向是通过带有window.location.replace() 的 JavaScript 完成的,因此您需要查看响应的正文:

    $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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-05
      • 2017-07-11
      • 1970-01-01
      • 2014-12-07
      • 2021-09-15
      • 2014-02-22
      • 2013-02-03
      • 1970-01-01
      相关资源
      最近更新 更多