조회 수 16351 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
<사용방법> 
1. php가 지원되는 계정에 본 파일을 업로드한다. (예:http://slrclub.com/cyworld.php) 
2. 싸이월드에 올려둔 사진의 url을 확인한다. url에서 서버위치와 파일 이름(redirect뒷 부분)을 복사한다. 
(예:http://cyimg.cyworld.nate.com/common/file_down.asp?redirect=%2Fd11003%2F2004%2F12%2F14%2F8%2FIMG%5F2904%2Ejpg) 
위의 예에서 host는 cyimg입니다. 예전 홈피의 경우 img일겁니다. 
3. 원하는 곳에 가서 img태그로 다음과 같이 연결한다. 
<img src="http://slrclub.com/cyworld.php?host=cyimg&redirect=%2Fd11003%2F2004%2F12%2F14%2F8%2FIMG%5F2904%2Ejpg" /> 
만약 host가 cyimg인 경우에는 host=cyimg&를 생략해도 됩니다. 

사용예: 싸이월드에 올려진 파일을 외부링크 걸고 싶을때 cyworld.php 라는 파일을 php가 지원되는 계정에 업로드 한 다음에 이 파일을 이용해서 불러들이면 됩니다. 

-- 소스 -- 
<? 
    if( !$redirect ) exit(); 
    if( !$host ) $host = "cyimg"; 
    
    $url = "http://".$host.".cyworld.nate.com/common/file_down.asp"; 
    
    $http = new Http; 
    $http->is_bin = 1; 
    $http->is_bin_len = 1024000; 
    $http->setURL( $url ); 
    $http->setParam("redirect", urldecode($redirect)); 
    $http->setCookie("ETC", "Referer=True"); // 쿠키 세팅 
    $result = $http->send("GET"); 
    echo( $result ); 
?> 
<? 
    /** 
    * HTTP 소켓 클래스 
    * 
    * @author 희망주기 (hopegiver@korea.com) 
    * @date 2002-09-06 
    * @access public 
    */ 
    class Http { 
        
        var $host; 
        var $port; 
        var $path; 
        var $cookie; 
        var $variable; 
        var $referer; 
        var $_header; 
        var $auth; 
        var $debug; 
        var $query; 
        var $is_bin; 
        var $is_bin_len; 
        
        # constructor 
        function Http($url="") { 
            $this->port = 80; 
            $this->is_bin = 0; 
            $this->is_bin_len = 102400; 
            if($url) $this->setURL($url); 
        } 
    
        /** 
        * URL 지정함수 
        * 
        * @param string $url : URL 
        * @return boolean 
        */ 
        function setURL($url) { 
            // if(!$m = parse_url($url)) return $this->setError("파싱이 불가능한 URL입니다."); 
            if(!$m = parse_url($url)) return 0; 
            // if($m['scheme'] != "http") return $this->setError("HTTP URL이 아닙니다."); 
            if($m['scheme'] != "http") return 0; 
            
            $this->host = $m['host']; 
            $this->port = ($m['port']) ? $m['port'] : 80; 
            $this->path = ($m['path']) ? $m['path'] : "/"; 
            if($m['query']) { 
                $arr1 = explode("&", $m['query']); 
                foreach($arr1 as $value) { 
                    $arr2 = explode("=", $value); 
                    $this->setParam($arr2[0], $arr2[1]); 
                } 
            } 
            if($m['user'] && $m['pass']) $this->setAuth($m['user'], $m['pass']); 
            
            return true; 
        } 
    
        /** 
        * 변수값을 지정한다. 
        * 
        * @param string $key : 변수명, 배열로도 넣을수 있다. 
        * @param string $value : 변수값 
        */ 
        function setParam($key, $value="") { 
            if(is_array($key)) foreach($key as $k => $v) $this->variable[$k] = $v; 
            else $this->variable[$key] = $value; 
        } 
        
        /** 
        * Referer를 지정한다. 
        * 
        * @param string $referer : Referer 
        */ 
        function setReferer($referer) { 
            $this->referer = $referer; 
        } 
    
        /** 
        * 쿠키를 지정한다. 
        * 
        * @param string $key : 쿠키변수명, 배열로도 넣을수 있다. 
        * @param string $value : 쿠키변수값 
        */ 
        function setCookie($key, $value="") { 
            if(is_array($key)) foreach($key as $k => $v) $this->cookie .= "; $k=$v"; 
            else $this->cookie .= "; $key=$value"; 
            if(substr($this->cookie, 0, 1) == ";") $this->cookie = substr($this->cookie, 2); 
        } 
        
        /** 
        * 인증설정함수 
        * 
        * @param string $id : 아이디 
        * @param string $pass : 패스워드 
        */ 
        function setAuth($id, $pass) { 
        $    this->auth = base64_encode($id.":".$pass); 
        } 
        
        /** 
        * POST 방식의 헤더구성함수 
        * 
        * @return string 
        */ 
        function postMethod() { 
            if(is_array($this->variable)) { 
                $parameter = "\r\n"; 
                foreach($this->variable as $key => $val) { 
                    $parameter .= trim($key)."=".urlencode(trim($val))."&"; 
                } 
                $parameter .= "\r\n"; 
            } 
            $query .= "POST ".$this->path." HTTP/1.0\r\n"; 
            $query .= "Host: ".$this->host."\r\n"; 
            if($this->auth) $query .= "Authorization: Basic ".$this->auth."\r\n"; 
            if($this->referer) $query .= "Referer: ".$this->referer."\r\n"; 
            if($this->cookie) $query .= "Cookie: ".$this->cookie."\r\n"; 
            $query .= "User-agent: PHP/HTTP_CLASS\r\n"; 
            $query .= "Content-type: application/x-www-form-urlencoded\r\n"; 
            $query .= "Content-length: ".strlen($parameter)."\r\n"; 
            if($parameter) $query .= $parameter; 
            $query .= "\r\n"; 
            return $query; 
        } 
        
        /** 
        * GET 방식의 헤더구성함수 
        * 
        * @return string 
        */ 
        function getMethod() { 
            if(is_array($this->variable)) { 
                $parameter = "?"; 
                foreach($this->variable as $key => $val) { 
                    $parameter .= trim($key)."=".urlencode(trim($val))."&"; 
                } 
                //$parameter = substr($parameter, 0, -1); 
            } 
            
            $query = "GET ".$this->path.$parameter." HTTP/1.0\r\n"; 
            $query .= "Host: ".$this->host."\r\n"; 
            if($this->auth) $query .= "Authorization: Basic ".$this->auth."\r\n"; 
            if($this->referer) $query .= "Referer: ".$this->referer."\r\n"; 
            if($this->cookie) $query .= "Cookie: ".$this->cookie."\r\n"; 
            $query .= "User-agent: PHP/HTTP_CLASS\r\n"; 
            $query .= "\r\n"; 
            return $query; 
        } 
        
        /** 
        * 데이타 전송함수 
        * 
        * @param string $mode : POST, GET 중 하나를 입력한다. 
        * @return string 
        */ 
        function send($mode="GET") { 
        
            // 웹서버에 접속한다. 
            $fp = fsockopen($this->host, $this->port, $errno, $errstr, 10); 
            // if(!$fp) return $this->setError($this->host."로의 접속에 실패했습니다."); 
            if(!$fp) return 0; 
            
            // GET, POST 방식에 따라 헤더를 다르게 구성한다. 
            if(strtoupper($mode) == "POST") $this->query = $this->postMethod(); 
            else $this->query = $this->getMethod(); 
            
            fputs($fp,$this->query); 
            
            // 헤더 부분을 구한다. 
            $this->_header = ""; // 헤더의 내용을 초기화 한다. 
            while(trim($buffer = fgets($fp,1024)) != "") { 
                $this->_header .= $buffer; 
            } 
            
            // 바디 부분을 구한다. 
            if( $this->is_bin ) { 
                $body = fread($fp, $this->is_bin_len); 
            } else { 
                while(!feof($fp)) { 
                $body .= fgets($fp,1024); 
                } 
            } 
        
            // 접속을 해제한다. 
            fclose($fp); 
        
            return $body; 
        } 
        
        /** 
        * 헤더를 구하는 함수 
        * 
        * @return string 
        */ 
        function getHeader() { 
            return $this->_header; 
        } 
        
        /** 
        * 쿠키값을 구하는 함수 
        * 
        * @param string $key : 쿠키변수 
        * @return string or array 
        */ 
        function getCookie($key="") { 
            if($key) { 
                $pattern = "/".$key."=([^;]+)/"; 
                if(preg_match($pattern, $this->_header, $ret)) return $ret[1]; 
            } else { 
                preg_match_all("/Set-Cookie: [^\n]+/", $this->_header, $ret); 
                return $ret[0]; 
            } 
        } 
    
    } 
?> 
-- / 소스 -- 
    
출처 : http://www.slrclub.com/

?

  1. [htm] DOM에 대해 ㅎㅎ

    Date2003.04.23 CategoryEtc Byhooni Views14718
    Read More
  2. [ios] 아이폰 개발 따라하기 ㅋㅋㅋ

    Date2013.04.23 CategoryEtc Byhooni Views23306
    Read More
  3. [link] iOS(아이폰) 개발 관련 ㅋㅋ

    Date2013.04.23 CategoryEtc Byhooni Views21505
    Read More
  4. [link] 유용한 사이트 링크.

    Date2013.08.19 CategoryEtc Byhooni Views71470
    Read More
  5. [NFC] 단말기와 서버 통신 내용

    Date2013.11.12 CategoryEtc Byhooni Views11194
    Read More
  6. [php] 싸이월드 이미지 외부 링크 하기(php)

    Date2013.04.23 CategoryEtc Byhooni Views16351
    Read More
  7. [svn] 콘솔에서 svn 사용시 레티나용 이미지 add 안될 때..

    Date2013.09.25 CategoryEtc Byhooni Views37503
    Read More
  8. [web] 제로보드 XE 템플릿에서 if문에 대해서 알아봅시다

    Date2013.08.16 CategoryEtc Byhooni Views19817
    Read More
  9. [세미나] XML 레포트..

    Date2003.04.23 CategoryEtc Byhooni Views19705
    Read More
  10. [용어] POC, Pilot, BMT에 대한 IT 업계에서 통용되는 의미

    Date2014.01.02 CategoryEtc Byhooni Views41963
    Read More
  11. 개발자가 알아야할 10가지 보안팁으로 코드 보호하기

    Date2013.04.23 CategoryEtc Byhooni Views16403
    Read More
  12. 논문(BHO)에 들어갈 내용 집에가서 테스트 해볼 것..

    Date2013.05.28 CategoryEtc Byhooni Views10230
    Read More
  13. 모바일 프로그래머가 갖추어야 할 필수 역량

    Date2017.02.16 CategoryEtc Byhooni Views1306
    Read More
  14. 베지어 곡선 (Bezier curve)

    Date2013.08.18 CategoryEtc Byhooni Views221506
    Read More
  15. 사이버보안실무 수업 메모

    Date2017.03.30 CategoryEtc Byhooni Views820
    Read More
  16. 사이버보안실무 시험.

    Date2017.04.20 CategoryEtc Byhooni Views0
    Read More
Board Pagination Prev 1 2 3 4 Next
/ 4