fsockopen
Language/PHP 2010. 8. 14. 01:01
<?
function url_fsockopen($host,$path) {
//$host : 도메인(IP)
//$path : 도메인(IP) 뒤에 붙는 주소값
$port = "7080";
//$host = "news.naver.com";
//$path = "/main/main.nhn?mode=LSD&mid=sec&sid1=105";
$out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n";
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
$out = "GET ".$path." HTTP/1.1\r\n";
$out .= "Host: ".$host."\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
$i = 0;
while (!feof($fp)) {
$result.= fgets($fp, 128);
//$i+=1;
}
fclose($fp);
return $result;
}
}
$line =url_fsockopen("news.naver.com","/main/main.nhn?mode=LSD&mid=sec&sid1=105");
echo trim($line);
?>
'Language > PHP' 카테고리의 다른 글
timestamp (0) | 2010.08.31 |
---|---|
substr (0) | 2010.08.19 |
Variable 함수 (0) | 2010.08.10 |
strtr 과 str_replace함수 차이 (0) | 2010.08.02 |
php.ini Session 옵션 (0) | 2010.08.02 |