사이트 내 전체검색
PHP
[php] URL이 살아 있는지 체크
로빈아빠
https://cmd.kr/php/513 URL이 복사되었습니다.

본문

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");
?>

댓글목록

등록된 댓글이 없습니다.

PHP
871 (9/18P)

Search

Copyright © Cmd 명령어 3.133.150.56