我沒測試,看到別人用CURL寫的,轉一下先,有空測試一下
function url_exists($url) {
$handle = curl_init($url);
if (false === $handle)
{
return false;
}
curl_setopt($handle, CURLOPT_HEADER, false);
curl_setopt($handle, CURLOPT_FAILONERROR, true); // this works
curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox
curl_setopt($handle, CURLOPT_NOBODY, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
$connectable = curl_exec($handle);
curl_close($handle);
return $connectable;
}
//判斷布爾值 驗證結果顯示 bool(true) bool(false)
$uri='http://www.rsywx.net/jquery/demos/index.html';
var_dump(url_exists($uri)); //true
$uri='http://www.rsywx.net/jquery/demos/index1.html';
var_dump(url_exists($uri)); //false