我有问题,这个剧本,如果我检查http://google.com/或其他网站未与http://stackoverflow.com工作,或cnn.com是工作...检查部位是向上或向下
$url = 'http://google.com/';
function urlExists($url=NULL)
{
if($url == NULL) return false;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode>=200 && $httpcode<300){
return true;
} else {
return false;
}
}
if(urlExists($url))
{
echo "ok";
}
else
{
echo "no";
}
我有测试@fopen
和不工作太
像谷歌网站有阻滞剂?由于
得益于与谷歌是好的,但与其他网站我有代码403,这是好吗?如果($ httpcode> = 200 && $ httpcode <= 403)? – user3710519
你也可以上到404(尽管它真的取决于脚本的意图)。你也可以做一些事情,比如'if($ httpcode = 200 || $ httpcode = 301 || $ httpcode = 403)'等等,下面是状态代码:http://www.w3.org/Protocols/rfc2616/ rfc2616-sec10.html –
谢谢你的家伙,并感谢所有的工作好:) – user3710519