Home > Backend Development > PHP Tutorial > php判断是否连接上网络的方法实例详解

php判断是否连接上网络的方法实例详解

PHPz
Release: 2018-09-30 17:56:00
forward
1231 people have browsed it

本文主要介绍PHP判断是否连接上网络的方法,通过php判断能否打开百度页面来判断是否连接上网络的功能,需要的朋友可以参考下

本文实例讲述了PHP判断是否连接上网络的方法。分享给大家供大家参考。具体实现方法如下:

首先写个函数

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

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

$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>"; 
}
Copy after login

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

更多相关教程请访问 php编程从入门到精通全套视频教程

Related labels:
php
source:jb51.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template