- <?php
- $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;
- $retVal = "";
- while (!feof ($fp)) {
- $tmp = fgets($fp, 1024);
- if ($start == true) $retVal .= $tmp;
- if ($tmp == "\r\n") $start = true;
- }
- fclose($fp);
- echo($retVal);
- ?>
추가적으로 GET 방식 호출은 다음과 같이 할 수도 있습니다.
- <?php
- $url = "URL 주소";
- $info = parse_url($url);
- $host = $info["host"];
- $port = $info["port"];
- if ($port == 0) $port = 80;
- $path = $info["path"];
- if ($info["query"] != "") $path .= "?" . $info["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);
- $start = false;
- $retVal = "";
- while(!feof($fp)) {
- $tmp = fgets($fp, 1024);
- if ($start == true) $retVal .= $tmp;
- if ($tmp == "\r\n") $start = true;
- }
- fclose($fp);
- echo $retVal;
- }
- ?>
기타 다른 방법으로는 .htaccess 파일을 이용하는 방법도 있더라구요..
.htaccess 파일에 다음과 같은 내용을 추가하면 된다고 합니다.
php_flag allow_url_fopen 1
'개발 > PHP' 카테고리의 다른 글
[html/php] 한페이지내 텝메뉴를 통한 구현 (0) | 2017.05.01 |
---|---|
버튼을 통한 아래 메뉴 혹은 탭 페이지 구현 (0) | 2017.05.01 |
input 동적 추가/삭제 하기 (0) | 2016.11.08 |
php 숫자 앞에 0 을 붙일때, sprintf 쓰자! (0) | 2016.11.03 |
자동 펼침메뉴 소스 (0) | 2016.11.02 |