Home  >  Article  >  Backend Development  >  A small example of PHP determining whether it is connected to the Internet

A small example of PHP determining whether it is connected to the Internet

WBOY
WBOYOriginal
2016-07-25 08:56:041050browse
  1. //Check whether the network is connected
  2. function varify_url($url){
  3. $check = @fopen($url,"r");
  4. if($check){
  5. $status = true;
  6. }else{
  7. $status = false;
  8. }
  9. return $status;
  10. } //by bbs.it-home.org
Copy code

Call example:

  1. $url = "http://bbs.it-home.org";
  2. if(varify_url($url)){
  3. echo "
    Congratulation ! Your URL < ;a href=$url>$url : is valid
    ";
  4. }else{
  5. echo "
    Error ! The URL you provided: $url is invalid
    ";
  6. }
Copy code


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