Home  >  Article  >  Backend Development  >  Detailed explanation of how PHP determines whether it is connected to the Internet

Detailed explanation of how PHP determines whether it is connected to the Internet

墨辰丷
墨辰丷Original
2018-05-29 15:29:451669browse

This article mainly introduces the method of PHP to determine whether it is connected to the Internet. It uses PHP to determine whether it can open the Baidu page to determine whether it is connected to the Internet. Friends who need it can refer to it.

The specific implementation method is as follows:

First write a function


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


Then call it directly where needed


$url = "http://www.baidu.com"; 
if(varify_url($url)){ 
 echo "<p>Congratulation ! Your URL <a href=$url>$url</a> : is <b>valid </b></p>"; 
}else{ 
 echo "<p>Error ! Your URL : <a href=$url>$url</a> is <b>invalid </b></p>"; 
}


The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

How to determine whether PHP is connected to the network, PHP determines whether to connect to the network

PHP method to determine whether to connect to the network, php to determine whether to connect to the network_PHP tutorial

PHP method to determine whether to connect to the network_PHP


The above is the detailed content of Detailed explanation of how PHP determines whether it is connected to the Internet. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn