我正在尝试了解页面的状态,无论该页面是重定向到任何其他域,还是停留在同一域中。但这对我没用。
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;
}发布于 2014-07-25 08:07:49
$ch = curl_init('url_here/');
curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (($code == 301) || ($code == 302)) { //301 and 302 specifies the redirects.
//your stuff
}查看更多关于here.的信息,也许你可以在这里找到答案
https://stackoverflow.com/questions/24950857
复制相似问题