因此,我正在運(yùn)行 URL 列表以檢查它們是否已失效或重定向,然后記錄結(jié)果。我也有一些例外,將重定向到 godaddy.com 或 hugedomains.com 等地方的域標(biāo)記為已死,因?yàn)樗鼈兓旧鲜沁@樣。我的問題是,它是參差不齊的。例如,域custommarbleproducts.comdanielharderandsons.com重定向到這些:http://danielharderandsons.com/?reqp=1&reqr=http://custommarbleproducts.com/?reqp=1&reqr=我嘗試過濾掉 "?reqp=1&reqr=" 并且它有時(shí)會(huì)起作用。我可以運(yùn)行腳本,在十個(gè)死/重定向 URL 中,四個(gè)將被標(biāo)記為死,然后重新運(yùn)行并有三個(gè)或五個(gè)標(biāo)記為死(結(jié)果不同,上次標(biāo)記為死的這次可能不會(huì)) ,我正在尋找更一致的結(jié)果。下面是函數(shù):function get_url_status($url) {$cookie = realpath(dirname(__FILE__)) . "/cookie.txt";file_put_contents($cookie, "");$ch = curl_init($url);curl_setopt($ch, CURLOPT_NOBODY, 1);if ($curl = curl_init()) { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // follow redirects curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // set referer on redirect curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $final_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); curl_close($ch); if ((strpos($final_url, "hugedomains.com") !== FALSE) || (strpos($final_url, "namecheap.com") !== FALSE) || (strpos($final_url, "uniregistry.com") !== FALSE) || (strpos($final_url, "afternic.com") !== FALSE) || (strpos($final_url, "buydomains.com") !== FALSE) || (strpos($final_url, "/?nr=0") !== FALSE) || (strpos($final_url, "?reqp=1&reqr=") !== FALSE) || (strpos($final_url, "godaddy.com") !== FALSE)) { return 'dead'; }有沒有人有任何想法使這更可靠?
1 回答

翻閱古今
TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個(gè)贊
也許比較原始 URL 和最終 URL 的域:
$orig_host = parse_url($url, PHP_URL_HOST);
$final_host = parse_url($final_url, PHP_URL_HOST);
$len = strlen($orig_host);
if (substr($final_host, 0 - $len) === $orig_host) {
echo "$final_host ends with $orig_host";
}
}
- 1 回答
- 0 關(guān)注
- 255 瀏覽
添加回答
舉報(bào)
0/150
提交
取消