PHP判断是否连接上网络

首先写个函数

function varify_url($url){
$check = @fopen($url,"r");
if($check){
 $status = true;
}else{
 $status = false;
}  
return $status;
}

接着在需要的地方直接调用即可

$url = "http://www.google.com";
if(varify_url($url)){
 echo "
Congratulation ! Your URL $url : is valid
"; }else{ echo "
Error ! Your URL : $url is invalid
"; }


你可能感兴趣的:(Php)