BACKRUSH  À¯´Ð½º¸í·É  ´ÙÀ½  ÀÚ·á½Ç  Ascii Table   ¿ø°ÝÁ¢¼Ó  ´Þ·Â,½Ã°£   ÇÁ·Î¼¼½º   ½©
ÁöÇÏö³ë¼±   RFC¹®¼­   SUN FAQ   SUN FAQ1   C¸Þ´º¾ó   PHP¸Þ´º¾ó   ³Ê±¸¸®   ¾Æ½ºÅ°¿ùµå ¾ÆÀÌÇǼ­Ä¡

±Û¾´ÀÌ: http http Á¢¼Ó CLASS[php] Á¶È¸¼ö: 14790


<?php
/**
* 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;

# constructor
function Http($url="") {
$this->port = 80;
if($url) $this->setURL($url);
}

function setError($errstr)
{
echo $errstr;
}

/**
* URL ÁöÁ¤ÇÔ¼ö
*
* @param string $url : URL
* @return boolean
*/
function setURL($url) {
if(!$m = parse_url($url)) return $this->setError("ÆĽÌÀÌ ºÒ°¡´ÉÇÑ URLÀÔ´Ï´Ù.");
if($m['scheme'] != "http") return $this->setError("HTTP URLÀÌ ¾Æ´Õ´Ï´Ù.");

$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."·ÎÀÇ Á¢¼Ó¿¡ ½ÇÆÐÇß½À´Ï´Ù.");

// 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;
}

// ¹Ùµð ºÎºÐÀ» ±¸ÇÑ´Ù.
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 = new Http;
$http->setDebug();
$http->setURL("http://www.zeto.co.kr/main/index.php?ch=main&skin=main");
$http->setCookie("ASPSESSIONIDGQGQGWJC", "FLFLJDMAOLEMKENOCCFDCKCH");
echo $http->send("GET");

*/

?>

°ü·Ã±Û : ¾øÀ½ ±Û¾´½Ã°£ : 2008/09/29 0:11 from 119.196.113.10

  GET/POST Àü¼Û ¸ñ·Ïº¸±â »õ±Û ¾²±â Áö¿ì±â ÀÀ´ä±Û ¾²±â ±Û ¼öÁ¤ Webtob, Jeus ¶óÀ̼¾½º ½Åû  
BACKRUSH  À¯´Ð½º¸í·É  ´ÙÀ½  ÀÚ·á½Ç  Ascii Table   ¿ø°ÝÁ¢¼Ó  ´Þ·Â,½Ã°£   ÇÁ·Î¼¼½º   ½©
ÁöÇÏö³ë¼±   RFC¹®¼­   SUN FAQ   SUN FAQ1   C¸Þ´º¾ó   PHP¸Þ´º¾ó   ³Ê±¸¸®   ¾Æ½ºÅ°¿ùµå ¾ÆÀÌÇǼ­Ä¡