1. 2011. 1. 1. 23:53 프로그래밍 언어/PHP
PHP 소켓을 이용한 크로스 도메인 코드의 단점은, 업로드,다운로드 트래픽이 중복 발생 한다는 것 입니다.
또한 iframe 으로 열거나 웹 페이지에서열 경우, 사용된 링크 파일들을 요청 하게 됩니다.

문제점을 충분히 이해한뒤에 사용 해주세요.
작성자 : Tanny Tales ( dudxo14@naver.com )

예를들어 request.html 파일에 아래 코드를 사용할경우.
주의 : UTF-8 파일 서명 등의 코드를 넣지 마세요. ( ex:  EF BB BF )
대상 페이지 인코딩 형태를 받아 헤더로 넘겨줍니다.
자바스크립트파일 을 이용할경우 UTF-8 형태로 인코딩하여 사용 하세요.
http://호스트주소/request.html?url_=
가져올주소&파라미터&referrer=리퍼러주소
ex: 네이버 카페 글 가져오기.
http://tanny.nayana.com/request.html?url_=http://cafe.naver.com/ArticleList.nhn&search.clubid=17552602&search.boardtype=L&referrer=http://cafe.naver.com/

<?php
function http_get($url,$referrer) 
{
  $url_stuff = parse_url($url); 
  $port = isset($url_stuff['port']) ? $url_stuff['port'] : 80
  $method = $_SERVER["REQUEST_METHOD"];
  $param = $_SERVER["QUERY_STRING"];
  if( $method == 'GET' ){
    $param = '?'.$param;
  }
  
  $fp = fsockopen($url_stuff['host'], $port); 

  $query  = "$method " . $url_stuff['path'].$param . " HTTP/1.1\r\n";
  $query .= 'Host: ' . $url_stuff['host'] ."\r\n";
  if( $referrer != NULL ){
    $query .= "referrer: ".$referrer."\r\n";
  }
  if( $param != NULL ){
    $query .= "Content-type: application/x-www-form-urlencoded\r\n";
    $query .= "Content-length: " . strlen($param) . "\r\n";
    $query .= "Connection: close\r\n\r\n";
    if( $method == 'POST' ){
      $query .= $param."\r\n";
    }
  }
  $query .= "\n\n"

  fwrite($fp, $query); 

  while($tmp = fgets($fp)){
    if(strlen($tmp) <= 2) break;
    header( $tmp );
  }
  while (($tmp = fgets($fp,4096)) !== false){
    echo $tmp;
  }
  fclose($fp);
/*  $charset=''; //소스코드 인코딩을 위한 부분
  //preg_match('/Content-Length: ([0-9]+)/', $buffer, $parts);
  preg_match( '@<meta\s+http-equiv="Content-Type"\s+content="([\w/]+)(;\s*charset=([^\s"]+))?@i', $header, $matches );
  //preg_match('@Content-Type:\s+([\w/+]+)(;*+charset=(\S+))?@i', $buffer, $matches );
  if ( isset( $matches[1] ) ) $mime = $matches[1];
  if ( isset( $matches[3] ) ) $charset = $matches[3];
  $header = substr($buffer, 0, -$parts[1]);
  if( $charset == 'utf-8' ){
    header(  $header );
    echo substr($buffer, -$parts[1]);
  }
  if( $charset == 'ks_c_5601-1987' ){
  }
  $charset = 'utf-8';
  echo iconv(NULL,$charset, substr($buffer, -$parts[1]));*/
}
http_get($_REQUEST['url_'],str_replace("%26","&",$_REQUEST['referrer']));
?>
Posted by Nightly Luna
,
® © Tanny Tales
/ rss