CURL 404(雅虎)

时间:2018-06-08 06:35:49

标签: php

我正在测试一个脚本,如果该域运行与否,我测试了50个站点(应该可以工作),但只有一个站点(Yahoo)返回“Died”(Not Working)并且它返回404,我是不确定问题是来自我的代码还是来自网站,我认为问题是“重定向”,但我不知道该怎么做。

我该如何关注它?

$host   = "www.yahoo.com";
    $ip     = gethostbyname($host);
    $domain = $ip;
    //Starting process to check the domain
    $check  = curl_init($domain);
    curl_setopt($check, CURLOPT_TIMEOUT, 10);
    curl_setopt($check, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($check, CURLOPT_RETURNTRANSFER, true);
    $data     = curl_exec($check);
    $httpcode = curl_getinfo($check, CURLINFO_HTTP_CODE);
    curl_close($check);
    if ($httpcode >= 200 && $httpcode <= 350) {
        $data_array[$key]['status'] = "Alive";
    } else {
        $data_array[$key]['status'] = "Died";
    }
}

1 个答案:

答案 0 :(得分:0)

我更改了网址,例如$ host =“www.yahoo.com/”;并添加了curl_setopt($ check,CURLOPT_FOLLOWLOCATION,1);它现在对我有用。