美文网首页
php监测网站是否可以访问

php监测网站是否可以访问

作者: 西湖凉咖啡 | 来源:发表于2018-03-12 06:09 被阅读19次

我的独立博客:https://blog.shenchenglin.cn/12.html

function httpcode($url){

$ch = curl_init();

  $timeout = 3;  curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

  curl_setopt($ch, CURLOPT_HEADER, 1);

  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

  curl_setopt($ch,CURLOPT_URL,$url);

  curl_exec($ch);

  return $httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);

  curl_close($ch);

}

$code = httpcode($url);

//echo httpcode($url);

if(empty($code)) {

echo'<center><p style="color:#FF0000;">此网站无法访问,请检查输入是否有误<p><center>';

exit;

}

相关文章

网友评论

      本文标题:php监测网站是否可以访问

      本文链接:https://www.haomeiwen.com/subject/qklgfftx.html