A function for checking the existence of a given URL. The usage of the function is similar to
file_exists. The only parameter of the function is the URL to be verified. The function returns true if the URL exists, else false.
<?php
/*=========================================================================*/
# A function for checking the existence of a given URL. The usage of the #
# function is similar to file_exists. The only parameter of the function #
# is the URL to be verified. The function returns true if the URL exists, #
# else false. #
/*=========================================================================*/
function url_exists($url)
{
$handle = @fopen($url, "r");
if ($handle === false)return false;
fclose($handle);
return true;
}
$url = isset($_GET['url']) ? $_GET['url'] : 'http://www.weberdev.com/';
?>
<html>
<head>
<title>URL Verification</title>
</head>
<body>
<table style="width:100%;height:100%;">
<tr><td>
<center><form method="get">
<?php
if(url_exists($url))
{
echo "<span style='color:green;font:bold 12px Verdana;'>$url is valid.</span><br><br>";
}else
{
echo "<span style='color:red;font:bold 12px Verdana;'>$url is invalid.</span><br><br>";
}
?>
<input type="text" name="url" size="35" value="<?php echo $url;?>"> <input type="submit" value="Go">
</form>
</center></td></tr></table>
</body>
</html>