Contents

조회 수 16347 댓글 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. [link] iOS(아이폰) 개발 관련 ㅋㅋ

    Date2013.04.23 CategoryEtc Byhooni Views21498
    Read More
  2. 이클립스(Eclipse) 유용한 단축키 ㅋㅋ

    Date2013.04.23 CategoryEtc Byhooni Views21757
    Read More
  3. 스파이웨어(BHO) 탐지하는 방법..

    Date2013.04.23 CategoryEtc Byhooni Views44388
    Read More
  4. 정보시스템(정보보안)의 위험관리 설명

    Date2013.04.23 CategoryEtc Byhooni Views19330
    Read More
  5. 양성/음성 오류에 대한 개념

    Date2013.04.23 CategoryEtc Byhooni Views19847
    Read More
  6. GSM에서 음성이 실리는 과정 요약..

    Date2013.04.23 CategoryEtc Byhooni Views17514
    Read More
  7. [php] 싸이월드 이미지 외부 링크 하기(php)

    Date2013.04.23 CategoryEtc Byhooni Views16347
    Read More
  8. [flash] 맘에 드는 파이차트

    Date2013.04.23 CategoryEtc Byhooni Views12588
    Read More
  9. [flash] 페이지 이동 (액션스크립트)

    Date2013.04.23 CategoryEtc Byhooni Views16261
    Read More
  10. [doc] 웜 프레임워크 검증환경 구축(작성중..)

    Date2013.04.23 CategoryEtc Byhooni Views16011
    Read More
  11. 여기저기서 모은 VoIP(인터넷전화) 자료들~

    Date2013.04.23 CategoryEtc Byhooni Views15964
    Read More
  12. 개발자가 알아야할 10가지 보안팁으로 코드 보호하기

    Date2013.04.23 CategoryEtc Byhooni Views16401
    Read More
Board Pagination Prev 1 2 3 4 5 6 Next
/ 6