How to check website status using PHP cURL

Today we are going to see about the website status, if you are having multi domains but want to check the website status its up or down.


You can go with below source code, which will tell you. Now we will create simple php file which have php and html code source. Our php script will check will valid url or not using filter_var function and getting header response from curl.

// declaring varaible and values
$q = '';
$str = '';
$strFlag = " DOWN";
$intFlag = 0;

// checking the btnSubmit is set value or not
if(isset($_GET["btnSubmit"])) {

	// assigning url for q variable
	$q = $_GET["q"];

	// checking the url in curl 
	$ch = curl_init ($q);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
	curl_exec ($ch);

	// getting url header response details
	$httpResponse = curl_getinfo($ch);

	// setting status code into array element
	$arrStatus = array(200,302);

	// validating url
	if(filter_var($q, FILTER_VALIDATE_URL)) {

	// comparing the http_code with array element with download content length 
		if(in_array($httpResponse["http_code"],$arrStatus) && $httpResponse["download_content_length"]>0) {
			$strFlag = " UP";
			$intFlag = 1;

	if($intFlag==1) {
		$str = $q." <br /> is <br /> ".$strFlag;

Now our html file which have text box and button to post the data and check the website status.

<title> - How to check website status using PHP curl</title>
<div align="center"><input type="text" name="q" size="75" value="<?php echo $q;?>" /> <input type="submit" name="btnSubmit" value="Check" /></div>
<div align="center" style="font-size:40px;background-color:#9ACD32;color:#FFFFFF;"><?php echo $str;?></div>

[ Download ] | [ Demo ]