'소스긁어오기'에 해당되는 글 1건

Posted on 2011/09/26 01:10 Url http://www.svkor.com/blog/3
Filed Under PHP

fsockopen() 함수를 이용해서 웹페이지로 접속하고, fgets() 함수를 이용하여 내용을 가져올 수 있다.
$fp = fsockopen("www.svkor.com", 80, $errno, $errstr, 30);
if (!$fp) die("$errstr ($errno)");

fputs($fp, "GET /blog/index.php HTTP/1.1\r\n");
fputs($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1)\r\n");
fputs($fp, "Host: www.svkor.com\r\n");
fputs($fp, "Connection: Closed\r\n");
fputs($fp, "\r\n");

$total = "";
while (!feof($fp)) {
	$temp = fgets($fp, 512);
	$temp = iconv("UTF-8", "CP949", $temp); // UTF-8인 경우
	$total .= $temp;
}

fclose($fp);

echo $total;

위 예제를 통해서 웹페이지 소스를 긁어올 수 있을것이다.
2011/09/26 01:10 2011/09/26 01:10

About

by 축복

Counter

· Total
: 6446
· Today
: 8
· Yesterday
: 28