url주소로 파일내용 읽어오기 [allow_url_fopen = off ]
컨텐츠 정보
- 18,481 조회
- 0 추천
- 목록
본문
<?
$url = "URL설정";
$info = parse_url($url);
$send = "POST ".$info[path]." HTTP/1.1\r\n"
. "Host: ".$info[host]."\r\n"
. "Content-type: application/x-www-form-urlencoded\r\n"
. "Content-length: ".strlen($info[query])."\r\n"
. "Connection: close\r\n\r\n".$info[query];
$fp = @fsockopen($info[host], 80);
fputs($fp, $send);
$start = false;
$return = "";
while(!feof($fp)) {
$tmp = fgets($fp, 1024);
if($start == true) $return .= $tmp;
if($tmp == "\r\n") $start = true;
}
@fclose($fp);
echo $return;
?>
or
allow_url_fopen = off 일때, 외부 파일 읽어오기
function get_url_fsockopen( $url ) {
$URL_parsed = parse_url($url);
$host = $URL_parsed["host"];
$port = $URL_parsed["port"];
if ($port==0)
$port = 80;
$path = $URL_parsed["path"];
if ($URL_parsed["query"] != "")
$path .= "?".$URL_parsed["query"];
$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 {
fputs($fp, $out);
$body = false;
while (!feof($fp)) {
$s = fgets($fp, 128);
if ( $body )
$in .= $s;
if ( $s == "\r\n" )
$body = true;
}
fclose($fp);
echo $in;
}
}
//참고 : phpcafe