【发布时间】:2014-09-17 00:29:39
【问题描述】:
我想知道页面的状态是重定向到任何其他域还是停留在同一个域中。但这对我不起作用。
https://www.rebelmouse.com/rohit/612798926.html
当我打开这个 url 时,它会将我重定向到其他域,我想检测它是停留在 rebelmouse.com 上还是打开任何其他域。
我尝试 curl_init() 来了解状态,但它给出了 200 它没有提供特定的 http 代码来识别重定向。
代码:
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$urlInfo = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
echo $urlInfo;
return $data;
}
【问题讨论】:
标签: php