PHP check if website is online

I am explaining you, how to check website availability/online with use of PHP and Curl. you can check if website is online/available in PHP. It uses PHP and cURL code. after check website’s status we can define it is online/available or not.

<?php
  function OnlineCheckWebSiteUrl($url){
    if(!filter_var($url, FILTER_VALIDATE_URL)){
      return false;
    }
    $ch = curl_init($url);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
    curl_setopt($ch,CURLOPT_HEADER,true);
    curl_setopt($ch,CURLOPT_NOBODY,true);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    $response = curl_exec($ch);
    curl_close($ch);
    return $response ? true : false;
  }echo "<br>";
  $url = 'https://webdeveloperindia.in';
  if(OnlineCheckWebSiteUrl($url)){
    echo 'Yes, website`s url is available/online';      
  }else{
     echo 'The web site is not available/online'; 
  }
?>

Output :

Yes, website`s url is available/online

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 47 = 50