Skip to content

URL이 살아 있는지 체크

MintState November 10, 2008 at 1:15 PM Views 14419

URL이 살아 있는지 체크

<?
function url_live($url)  
{

// 000 : only http://
// 001 checkdnsrr error
// 002 fsockopen error
// other : http return code

if ($url == "http://") return "000";
$parsed = parse_url($url); 
$host = $parsed["host"];
$path = $parsed["path"];

if (!$path) $path = "/";


if (!(checkdnsrr($host,"A"))) return "001";

$fp = fsockopen ($host, 80,$errno, $errstr, 10) ;
if (!$fp) return "002";

fputs($fp,"GET $path HTTP/1.0\n\n");  

$line = fgets($fp, 1024);  
	 
	 if (eregi( "^http/[0-9]+.[0-9]+ ([0-9]{3}) [a-z ]*", $line)) {
	 $return =   trim(eregi_replace( "^http/[0-9]+.[0-9]+ ([0-9]{3}) [a-z ]*",  "\\1", $line));
	}
	else 	{
	$return = "000";
	}

fclose($fp);  
return $return;
}  

echo url_live("http://yesyo.com");
?>
Share X Facebook LINE QR code

0 comments

Be the first to comment.