I know two codes:
-first is simple
<?
function checkurl($url)
{
$phpnet = fsockopen($url, 80, &$errno, &$errstr, 30);
if(!$phpnet) {
echo "<b>php.net <font color=\"red\">D ead link!</font></b>\n"; }
else {
echo("<a href=\"http://".$url."\">".$u rl."</a>");
}
}
?>
-second more complex
<?
$text['N/A'] = "URL is not HTTP";
$text[OK] = "OK";
$text[FAIL] = "FAIL";
$text[DNS] = "Server not resolve";
$text[100] = "Continue";
$text[101] = "Switching Protocols";
$text[200] = "OK";
$text[201] = "Created";
$text[202] = "Accepted";
$text[203] = "Non-Authoritative Information";
$text[204] = "No Content";
$text[205] = "Reset Content";
$text[206] = "Partial Content";
$text[300] = "Multiple Choices";
$text[301] = "Moved Permanently";
$text[302] = "Found";
$text[303] = "See Other";
$text[304] = "Not Modified";
$text[305] = "Use Proxy";
$text[307] = "Temporary Redirect";
$text[400] = "Bad Request";
$text[401] = "Unauthoriz ed";
$text[402] = "Payment Required";
$text[403] = "Forbidden" ;
$text[404] = "Not Found";
$text[405] = "Method Not Allowed";
$text[406] = "Not Acceptable";
$text[407] = "Proxy Authentication Required";
$text[408] = "Request Timeout";
$text[409] = "Conflict";
$text[410] = "Gone";
$text[411] = "Length Required";
$text[412] = "Preconditi on Failed";
$text[413] = "Request Entity Too Large";
$text[414] = "Request-URI Too Long";
$text[415] = "Unsupporte d Media Type";
$text[416] = "Requested Range Not Satisfiable";
$text[417] = "Expectatio n Failed";
$text[500] = "Internal Server Error";
$text[501] = "Not Implemented";
$text[502] = "Bad Gateway";
$text[503] = "Service Unavailable";
$text[504] = "Gateway Timeout";
$text[505] = "HTTP Version Not Supported";
function check($url) {
if (eregi( "^<a href="ftp://" target="_blank" >ftp://</a>", $url)) {
$urlArray = parse_url($url) ;
$host = $urlArray[host]; $user = $urlArray[user]; $pass =
$urlArray[pass];
if ($user == "") { $user="anonymou s"; $pass="de***@ps .xaos.ru"; }
$ftp = ftp_connect($ho st);
if ($ftp && ftp_login($ftp, $user, $pass)) {
$list = ftp_nlist($ftp, $urlArray[path]);
if ($list[0]!="") {
$return[code] = "OK"; return $return;
} else { $return[code] = "FAIL"; return $return;}
} else { $return[code] = "DNS"; return $return;}
}
if (eregi( "^<a href="http://" target="_blank" >http://</a>", $url)) {
$urlArray = parse_url($url) ;
if (!$urlArray[port]) $urlArray[port] = "80";
if (!$urlArray[path]) $urlArray[path] = "/";
$sock = fsockopen($urlA rray[host], $urlArray[port], &$errnum,
&$errstr);
if (!$sock) $return[code] = "DNS";
else {
$dump .= "GET $urlArray[path] HTTP/1.1
";
$dump .= "Host: $urlArray[host]
Connection: close
";
$dump .= "Connection : close
";
fputs($sock, $dump);
while ($str = fgets($sock, 1024)) {
if (eregi("^http/[0-9]+.[0-9]+ ([0-9]{3}) [a-z ]*", $str))
$return[code] = trim(eregi_repl ace("^http/[0-9]+.[0-9]+
([0-9]{3}) [a-z ]*", "\1", $str));
if (eregi("^Conten t-Type: ", $str))
$return[contentType] = trim(eregi_repl ace("^Content-Type: ",
"", $str));
}
fclose($sock);
flush();
}
} else $return[code] = "N/A";
return $return;
}
$res = check (stripslashes($ url));
echo "Checking - ".stripslashes( $url)." :: Status - ".$text[$res[code]];
?>
"Jay" <ar********@yah oo.com> ???????/???????? ? ???????? ?????????:
news:56******** *************** ***@posting.goo gle.com...
Hi !
I am a beginner in PHP. Does anybody know how to check if an URL is
alive or dead in PHP (not exist or server down...or whatever ) ?
Any help would be appreciated !
Thanks !
Jay