Sometmes i just look around allday for snippet that could come in use latter on and add them to a Snippet in dreamweaver so try cehckotu some script sites in you free time too 🙂
this will work if you edit to you needed:
<?
/**
* check_link()
* code by J. Waite 2003
*
* Checks the URL and reports back the HTTP response code like: "HTTP/1.1 200 OK"
* Or "Failed" if URL doesn't connect.
*
* example:
* echo check_link("www.php.net");
*
* @param string $url
* @return string $output
**/
function check_link($url)
{
// set the output variable
$output = "";
// convert the url to lower case
$url = strtolower($url);
// check if the url is an ftp and remove "ftp://"
if (strstr($url, "ftp://") || strstr($url, "ftp.")) {
$url = str_replace("ftp://", "", $url);
// seperate the url by the slash
$url = explode("/", $url);
// use only the first occurance of url after seperation.
// open a connection to the url
if ($fp = ftp_connect($url[0])) {
// close the connection
ftp_close($fp);
$output = "FTP connection valid";
} else {
$output = "Failed";
}
// url is not an ftp link.
} else {
// add "http://" if its missing.
$url = (strstr($url, "http://")) ? $url : "http://" . $url;
// open a connection to the url.
if ($fp = @fopen($url,"r")) {
// if php version is newer then 4.3.0 do socket_get_status.
if (version_compare(phpversion(), '4.3.0') > 0) {
$socket = socket_get_status($fp);
// return just the http response code.
$output = $socket['wrapper_data'][0];
} else {
// older php version
$output = "Connection is valid";
}
// close the connection
fclose($fp);
} else {
$output = "Failed";
}
}
// return output status.
return $output;
}
?>