【问题标题】:PHP get final redirect urlPHP 获取最终重定向 url
【发布时间】:2015-09-30 12:19:44
【问题描述】:
【问题讨论】:
标签:
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