我没测试,看到别人用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