Website status checker php script

Hi friends, in my previous blog I show you how to create newsletter subscription using PHP, Ajax, jQuery. Today I will show you how to check any website current status or you can say website status checker php script. Using this small application you can check any website current status. In this application I use cURL. So before using this script please know how to use cURL. So now I start the application.

In this application I create a form where user put website url. After submitting the form I am using cURL to check the HTTP status code. Using this status code you can get the website/Url status



<?php
function check_url($url)
{
	$st = curl_init($url); 
	curl_setopt($st, CURLOPT_NOBODY, true);
	curl_setopt($st, CURLOPT_FOLLOWLOCATION, true);
	curl_exec($st);
	
	$responce_code = curl_getinfo($st, CURLINFO_HTTP_CODE);
	return $responce_code;
}
 
if((isset($_POST['submit']) == true) && (isset($_POST['website_url']) == true))
{
	$website_url = trim($_POST['website_url']);
	if (preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website_url))
	{
		switch(check_url($website_url))
		{
			case 200:
			$message = '<div class="success"><h3>'.$website_url.' is up and running.</h3></div>';
			break;
			case 400:
			$message = '<div class="error"><h3>Bad request from Website.</h3></div>';
			break;
			case 401:
			$message = '<div class="error"><h3>Unauthorized Website.</h3></div>';
			break;
			case 403:
			$message = '<div class="error"><h3>Forbidden Website.</h3></div>';
			break;
			case 404:
			$message = '<div class="error"><h3>Not Found.</h3></div>';
			break;
			case 500:
			$message = '<div class="error"><h3>Internal Server Error.</h3></div>';
			break;
			default:
			$message = '<div class="error"><h3>Some thing went wrong, '.$website_url.' down.</h3></div>';
		}
	} else {
		$message = '<div class="error"><h3>Invalid Website Address.</h3></div>';
	}
}
?>

<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<title>website status checking</title>
	<link rel="stylesheet" href="css/style.css" />
</head>
<body>
	<div class="serch-wrap">
		<div class="form-wrapper cf">
			<?php if(isset($message)) echo $message;?>
			<form action="" method="POST">
				<input type="text" name="website_url" placeholder="www.google.com" autocomplete="off" />
				<input type="submit" name="submit" value="Check"/>
			</form>
		</div>
	</div>
</body>
</html>

Demo
Download

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •