팁앤텍
소켓이용 post, get 방식으로 내용 받아오는 클래스
GET, POST를 이용해 내용을 받아오는 클래스 조회수:2806
검색해보니 나오긴 하는데 제가 필요한 기능을 갖추지 못했더군요.
그래서 제가 필요한 대로 급조해봤습니다.
혹여나 필요하신 분 있을까 해서 올려봅니다. 참조하시기 바랍니다.
사용 예:
server = “phpschool.com”;
$http->port = 80;
$http->method = “get”; // POST를 사용하시려면 post로 변경해 주세요.
$http->path = “/bbs2/inc_board.html”;
$http->header[“Accept”] = “image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*”;
$http->header[“Referer”] = “http://phpschool.com/”;
$http->header[“Accept-Language”] = “ko”;
$http->header[“Content-Type”] = “application/x-www-form-urlencoded”;
$http->header[“User-Agent”] = “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)”;
$http->header[“Host”] = $http->server;
$http->header[“Connection”] = “Keep-Alive”;
$http->header[“Cache-Control”] = “no-cache”;
$http->variable[“code”] = “tnt2”;
$http->openSock();
$data_get = $http->getPage();
echo nl2br(htmlspecialchars($data));
?>
——————————————————————–
class.network.get_Page.php
——————————————————————–
var $server;
var $port;
var $method;
var $sock;
var $path;
var $header = array();
var $variable = array();
var $cmd;
var $config;
function http_get_Page() {
$this->port = 80;
$this->method = “get”;
$this->path = “/”;
$this->config = array(
“version” => “1.0”,
“name” => “Get files through http protocol”,
“debugname” => “class.network.get_Page.php”,
);
}
function openSock() {
$this->sock = @fsockopen($this->server, $this->port);
if (!$this->sock) $this->Error(“Cannot open socket [$this->server:$this->port]”);
}
function getPage() {
if (eregi(“GET”, $this->method)) {
if ($this->variable) {
$aid_url = “?”;
foreach ($this->variable as $key => $value) {
$key = urlencode($key);
$value = urlencode($value);
if ($aid_url == “?”) $aid_url .= $key.”=”.$value;
else $aid_url .= “&”.$key.”=”.$value;
}
}
$cmd = “GET “.$this->path.$aid_url.” HTTP/1.1″;
if (!$this->header) $this->Error(“No Any HTTP Headers.”);
foreach ($this->header as $key => $value) {
$cmd .= “
“.$key.”: “.$value;
}
$cmd .= “
“;
}
if (eregi(“POST”, $this->method)) {
if ($this->variable) {
$aid_query = “”;
foreach ($this->variable as $key => $value) {
$key = urlencode($key);
$value = urlencode($value);
if (!$aid_query) $aid_query .= $key.”=”.$value;
else $aid_query .= “&”.$key.”=”.$value;
}
}
$cmd = “POST “.$this->path.” HTTP/1.1″;
if (!$this->header) $this->Error(“No Any HTTP Headers.”);
$strlen = strlen($aid_query);
$this->header[“Content-Length”] = $strlen;
foreach ($this->header as $key => $value) {
$cmd .= “
“.$key.”: “.$value;
}
$cmd .= “
“;
$cmd .= $aid_query;
}
fputs($this->sock, $cmd);
$str_get = “”;
while (!feof($this->sock)) {
$str_get .= fgets($this->sock, 1024);
}
return $str_get;
}
function Error($message) {
die ($this->config[debugname].” Error: “.$message);
}
}
?>
디버깅목적의 테이블 보더 표시하기
| 정말정말 | ||
| 복잡하게도 | 만들어 | 놓은 |
| TABLE | 구조를 | |
| 보기 | 편하게 | 만들어줍니다. |
| 여기에도 | 또하나의 | 테이블이 |
| 조금 | 복잡하게 | |
| 만들어져 있군요. | ||
위 코드를 실행하면 테이블위에 마우스커서가 위치할때 붉은색 라인으로
테이블 보더가 표시됩니다. 디버깅시 유용하게..
iframe 크기조절 – be more dynamic
http://example.debugs.co.kr/html/example/iframeheight/frame.html
http://example.debugs.co.kr/html/example/iframeheight/content.html
재미난 내용인거같아 저도한번 올려봅니다.
ie 5.0 이상부터 제공되기 시작한 css지시자 expression 또는 setExpression 메소드를 이용하면 좀더 심플하게, 동적으로 변화를 감지할 수 있습니다.
예제를 보시려면 링크#1을 클릭해보세요
setTimeout 없이도 내용의 변화가 즉각 반영되는것을 알 수 있습니다.
expression 을 이용해서 로그인박스 처리나 게시판 입력항목같은 좀더 재미난 부분에 응용이 가능한데.. 그 부분은 나중에 시간이 나면 예제와 함께 소개해 보겠습니다 : )
[소스: frame.html]
[/소스]
[소스:content.html]
…
이것은 iframe 내용입니다.
이것은 iframe 내용입니다.
이것은 iframe 내용입니다.
이것은 iframe 내용입니다.