지정 url의 소스를 긁어오는 함수

function getURLPage($URL)
{
global $HTTP_COOKIE;

$pos = strpos($URL, “/”);
$server = trim(substr($URL, 0, $pos));
$path = trim(substr($URL, $pos));
if(!strlen($path)) $path=”/”;

$fp = fsockopen($server, 80, &$errno, &$errstr);
if(!$fp) return ;
$header .= “GET $path HTTP/1.0
“;
$header .= “Host: $server
“;
$header .= “Content-Type: text/html
“;
$header .= “User-Agent: Kwangho Get Robot
“;
$header .= “From: dynamic@netso.co.kr
“;
$header .= “Cookie: $HTTP_COOKIE;

“;
fputs($fp,$header);

$ret = “”;
while(!feof($fp))
{
$ctr=fgets($fp, 1024);
if ($ok) $ret .= $ctr;
if (strstr($ctr, “HTTP/1.1 404”) && !$ok) break;
if (strstr($ctr, “Content-Type: text/html”)) $ok=1;
}
fclose($fp);

return $ret ;

}