PHP函数来判断这个网站是否能正常打开
( 更新:04-18 加入收藏)
<?php
$slurl = 'https://www.bingdou.com.cn';
$ch = curl_init();
$timeout = 10;
curl_setopt ($ch, CURLOPT_URL, $slurl);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
if(false == $contents){?>无法访问
<?php }else{?>可以访问
<?php }?>
上一篇:PHP获取当前网页的标题和内容