NewsNewsFeaturesDownloadsDevelopmentSupportForumDocumentsAbout Us

HttpClient 類別 參考文件
[Net_HTTP]

全部成員列表

公開方法(Public Methods)

 HttpClient ()
 fetch ($URI)
 submit ($URI, $formvars="", $formfiles="")
 fetchlinks ($URI)
 fetchform ($URI)
 fetchtext ($URI)
 submitlinks ($URI, $formvars="", $formfiles="")
 submittext ($URI, $formvars="", $formfiles="")
 set_submit_multipart ()
 set_submit_normal ()
 _striplinks ($document)
 _stripform ($document)
 _striptext ($document)
 _expandlinks ($links, $URI)
 _httprequest ($url, $fp, $URI, $http_method, $content_type="", $body="")
 _httpsrequest ($url, $URI, $http_method, $content_type="", $body="")
 setcookies ()
 _check_timeout ($fp)
 _connect (&$fp)
 _disconnect ($fp)
 _prepare_post_body ($formvars, $formfiles)

公開屬性

 $host = "www.php.net"
 $port = 80
 $proxy_host = ""
 $proxy_port = ""
 $agent = "Snoopy v1.0"
 $referer = ""
 $cookies = array()
 $rawheaders = array()
 $maxredirs = 5
 $lastredirectaddr = ""
 $offsiteok = true
 $maxframes = 0
 $expandlinks = true
 $passcookies = true
 $user = ""
 $pass = ""
 $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"
 $results = ""
 $error = ""
 $response_code = ""
 $headers = array()
 $maxlength = 500000
 $read_timeout = 0
 $timed_out = false
 $status = 0
 $curl_path = "/usr/local/bin/curl"
 $_maxlinelen = 4096
 $_httpmethod = "GET"
 $_httpversion = "HTTP/1.0"
 $_submit_method = "POST"
 $_submit_type = "application/x-www-form-urlencoded"
 $_mime_boundary = ""
 $_redirectaddr = false
 $_redirectdepth = 0
 $_frameurls = array()
 $_framedepth = 0
 $_isproxy = false
 $_fp_timeout = 30

詳細描述

The HttpClient is based on the Snoopy class for making HTTP requests. It is very basic in the sense that it does not have support for proxies or anything like that, but it works just fine.

Snoopy - the PHP net client Author: Monte Ohrt <monte@ispi.net> Copyright (c): 1999-2000 ispi, all rights reserved Version: 1.0

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

定義在 httpclient.class.php 檔案之第 29 行.


建構子與解構子說明文件

HttpClient::HttpClient  ) 
 

定義在 httpclient.class.php 檔案之第 104 行.

00105     {
00106         // does nothing :)
00107     }


函式成員說明文件

HttpClient::_check_timeout fp  ) 
 

定義在 httpclient.class.php 檔案之第 1026 行.

01027     {
01028         if ($this->read_timeout > 0) {
01029             $fp_status = socket_get_status($fp);
01030             if ($fp_status["timed_out"]) {
01031                 $this->timed_out = true;
01032                 return true;
01033             }
01034         }
01035         return false;
01036     }

HttpClient::_connect &$  fp  ) 
 

定義在 httpclient.class.php 檔案之第 1044 行.

參考 $host.

被參考於 fetch(), 及 submit().

01045     {
01046         if(!empty($this->proxy_host) && !empty($this->proxy_port))
01047             {
01048                 $this->_isproxy = true;
01049                 $host = $this->proxy_host;
01050                 $port = $this->proxy_port;
01051             }
01052         else
01053         {
01054             $host = $this->host;
01055             $port = $this->port;
01056         }
01057     
01058         $this->status = 0;
01059         
01060         if($fp = fsockopen(
01061                     $host,
01062                     $port,
01063                     $errno,
01064                     $errstr,
01065                     $this->_fp_timeout
01066                     ))
01067         {
01068             // socket connection succeeded
01069 
01070             return true;
01071         }
01072         else
01073         {
01074             // socket connection failed
01075             $this->status = $errno;
01076             switch($errno)
01077             {
01078                 case -3:
01079                     $this->error="socket creation failed (-3)";
01080                 case -4:
01081                     $this->error="dns lookup failure (-4)";
01082                 case -5:
01083                     $this->error="connection refused or timed out (-5)";
01084                 default:
01085                     $this->error="connection failed (".$errno.")";
01086             }
01087             return false;
01088         }
01089     }

HttpClient::_disconnect fp  ) 
 

定義在 httpclient.class.php 檔案之第 1096 行.

被參考於 fetch(), 及 submit().

01097     {
01098         return(fclose($fp));
01099     }

HttpClient::_expandlinks links,
URI
 

定義在 httpclient.class.php 檔案之第 683 行.

被參考於 fetchlinks(), submit(), 及 submitlinks().

00684     {
00685         
00686         preg_match("/^[^\?]+/",$URI,$match);
00687 
00688         $match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]);
00689                 
00690         $search = array(    "|^http://".preg_quote($this->host)."|i",
00691                             "|^(?!http://)(\/)?(?!mailto:)|i",
00692                             "|/\./|",
00693                             "|/[^\/]+/\.\./|"
00694                         );
00695                         
00696         $replace = array(   "",
00697                             $match."/",
00698                             "/",
00699                             "/"
00700                         );          
00701                 
00702         $expandedLinks = preg_replace($search,$replace,$links);
00703 
00704         return $expandedLinks;
00705     }

HttpClient::_httprequest url,
fp,
URI,
http_method,
content_type = "",
body = ""
 

定義在 httpclient.class.php 檔案之第 717 行.

參考 $url.

被參考於 fetch(), 及 submit().

00718     {
00719         if($this->passcookies && $this->_redirectaddr)
00720             $this->setcookies();
00721             
00722         $URI_PARTS = parse_url($URI);
00723         if(empty($url))
00724             $url = "/";
00725         $headers = $http_method." ".$url." ".$this->_httpversion."\r\n";        
00726         if(!empty($this->agent))
00727             $headers .= "User-Agent: ".$this->agent."\r\n";
00728         if(!empty($this->host) && !isset($this->rawheaders['Host']))
00729             $headers .= "Host: ".$this->host."\r\n";
00730         if(!empty($this->accept))
00731             $headers .= "Accept: ".$this->accept."\r\n";
00732         if(!empty($this->referer))
00733             $headers .= "Referer: ".$this->referer."\r\n";
00734         if(!empty($this->cookies))
00735         {           
00736             if(!is_array($this->cookies))
00737                 $this->cookies = (array)$this->cookies;
00738     
00739             reset($this->cookies);
00740             if ( count($this->cookies) > 0 ) {
00741                 $cookie_headers .= 'Cookie: ';
00742                 foreach ( $this->cookies as $cookieKey => $cookieVal ) {
00743                 $cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; ";
00744                 }
00745                 $headers .= substr($cookie_headers,0,-2) . "\r\n";
00746             } 
00747         }
00748         if(!empty($this->rawheaders))
00749         {
00750             if(!is_array($this->rawheaders))
00751                 $this->rawheaders = (array)$this->rawheaders;
00752             while(list($headerKey,$headerVal) = each($this->rawheaders))
00753                 $headers .= $headerKey.": ".$headerVal."\r\n";
00754         }
00755         if(!empty($content_type)) {
00756             $headers .= "Content-type: $content_type";
00757             if ($content_type == "multipart/form-data")
00758                 $headers .= "; boundary=".$this->_mime_boundary;
00759             $headers .= "\r\n";
00760         }
00761         if(!empty($body))   
00762             $headers .= "Content-length: ".strlen($body)."\r\n";
00763         if(!empty($this->user) || !empty($this->pass))  
00764             $headers .= "Authorization: BASIC ".base64_encode($this->user.":".$this->pass)."\r\n";
00765 
00766         $headers .= "\r\n";
00767         
00768         // set the read timeout if needed
00769         if ($this->read_timeout > 0)
00770             socket_set_timeout($fp, $this->read_timeout);
00771         $this->timed_out = false;
00772         
00773         fwrite($fp,$headers.$body,strlen($headers.$body));
00774         
00775         $this->_redirectaddr = false;
00776         unset($this->headers);
00777                         
00778         while($currentHeader = fgets($fp,$this->_maxlinelen))
00779         {
00780             if ($this->read_timeout > 0 && $this->_check_timeout($fp))
00781             {
00782                 $this->status=-100;
00783                 return false;
00784             }
00785                 
00786             if($currentHeader == "\r\n")
00787                 break;
00788                         
00789             // if a header begins with Location: or URI:, set the redirect
00790             if(preg_match("/^(Location:|URI:)/i",$currentHeader))
00791             {
00792                 // get URL portion of the redirect
00793                 preg_match("/^(Location:|URI:)\s+(.*)/",chop($currentHeader),$matches);
00794                 // look for :// in the Location header to see if hostname is included
00795                 if(!preg_match("|\:\/\/|",$matches[2]))
00796                 {
00797                     // no host in the path, so prepend
00798                     $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port;
00799                     // eliminate double slash
00800                     if(!preg_match("|^/|",$matches[2]))
00801                             $this->_redirectaddr .= "/".$matches[2];
00802                     else
00803                             $this->_redirectaddr .= $matches[2];
00804                 }
00805                 else
00806                     $this->_redirectaddr = $matches[2];
00807             }
00808         
00809             if(preg_match("|^HTTP/|",$currentHeader))
00810             {
00811                 if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status))
00812                 {
00813                     $this->status= $status[1];
00814                 }               
00815                 $this->response_code = $currentHeader;
00816             }
00817                 
00818             $this->headers[] = $currentHeader;
00819         }
00820 
00821         //$results = fread($fp, $this->maxlength);
00822         $results = "";
00823         while(!feof($fp)) {
00824             $results .= fgets($fp, 128);
00825         }
00826  
00827  
00828  
00829  
00830 
00831 
00832         if ($this->read_timeout > 0 && $this->_check_timeout($fp))
00833         {
00834             $this->status=-100;
00835             return false;
00836         }
00837         
00838         // check if there is a a redirect meta tag
00839         
00840         if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]+URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
00841         {
00842             $this->_redirectaddr = $this->_expandlinks($match[1],$URI); 
00843         }
00844 
00845         // have we hit our frame depth and is there frame src to fetch?
00846         if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\">]+)'i",$results,$match))
00847         {
00848             $this->results[] = $results;
00849             for($x=0; $x<count($match[1]); $x++)
00850                 $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host);
00851         }
00852         // have we already fetched framed content?
00853         elseif(is_array($this->results))
00854             $this->results[] = $results;
00855         // no framed content
00856         else
00857             $this->results = $results;
00858         
00859         return true;
00860     }

HttpClient::_httpsrequest url,
URI,
http_method,
content_type = "",
body = ""
 

定義在 httpclient.class.php 檔案之第 871 行.

參考 $url.

被參考於 fetch(), 及 submit().

00872     {
00873         if($this->passcookies && $this->_redirectaddr)
00874             $this->setcookies();
00875 
00876         $headers = array();     
00877                     
00878         $URI_PARTS = parse_url($URI);
00879         if(empty($url))
00880             $url = "/";
00881         // GET ... header not needed for curl
00882         //$headers[] = $http_method." ".$url." ".$this->_httpversion;       
00883         if(!empty($this->agent))
00884             $headers[] = "User-Agent: ".$this->agent;
00885         if(!empty($this->host))
00886             $headers[] = "Host: ".$this->host;
00887         if(!empty($this->accept))
00888             $headers[] = "Accept: ".$this->accept;
00889         if(!empty($this->referer))
00890             $headers[] = "Referer: ".$this->referer;
00891         if(!empty($this->cookies))
00892         {           
00893             if(!is_array($this->cookies))
00894                 $this->cookies = (array)$this->cookies;
00895     
00896             reset($this->cookies);
00897             if ( count($this->cookies) > 0 ) {
00898                 $cookie_str = 'Cookie: ';
00899                 foreach ( $this->cookies as $cookieKey => $cookieVal ) {
00900                 $cookie_str .= $cookieKey."=".urlencode($cookieVal)."; ";
00901                 }
00902                 $headers[] = substr($cookie_str,0,-2);
00903             }
00904         }
00905         if(!empty($this->rawheaders))
00906         {
00907             if(!is_array($this->rawheaders))
00908                 $this->rawheaders = (array)$this->rawheaders;
00909             while(list($headerKey,$headerVal) = each($this->rawheaders))
00910                 $headers[] = $headerKey.": ".$headerVal;
00911         }
00912         if(!empty($content_type)) {
00913             if ($content_type == "multipart/form-data")
00914                 $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary;
00915             else
00916                 $headers[] = "Content-type: $content_type";
00917         }
00918         if(!empty($body))   
00919             $headers[] = "Content-length: ".strlen($body);
00920         if(!empty($this->user) || !empty($this->pass))  
00921             $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass);
00922             
00923         for($curr_header = 0; $curr_header < count($headers); $curr_header++)
00924             $cmdline_params .= " -H \"".$headers[$curr_header]."\"";
00925         
00926         if(!empty($body))
00927             $cmdline_params .= " -d \"$body\"";
00928         
00929         if($this->read_timeout > 0)
00930             $cmdline_params .= " -m ".$this->read_timeout;
00931         
00932         $headerfile = uniqid(time());
00933 
00934         exec($this->curl_path." -D \"/tmp/$headerfile\"".$cmdline_params." ".$URI,$results,$return);
00935         
00936         if($return)
00937         {
00938             $this->error = "Error: cURL could not retrieve the document, error $return.";
00939             return false;
00940         }
00941             
00942             
00943         $results = implode("\r\n",$results);
00944         
00945         $result_headers = file("/tmp/$headerfile");
00946                         
00947         $this->_redirectaddr = false;
00948         unset($this->headers);
00949                         
00950         for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++)
00951         {
00952             
00953             // if a header begins with Location: or URI:, set the redirect
00954             if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader]))
00955             {
00956                 // get URL portion of the redirect
00957                 preg_match("/^(Location: |URI:)(.*)/",chop($result_headers[$currentHeader]),$matches);
00958                 // look for :// in the Location header to see if hostname is included
00959                 if(!preg_match("|\:\/\/|",$matches[2]))
00960                 {
00961                     // no host in the path, so prepend
00962                     $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port;
00963                     // eliminate double slash
00964                     if(!preg_match("|^/|",$matches[2]))
00965                             $this->_redirectaddr .= "/".$matches[2];
00966                     else
00967                             $this->_redirectaddr .= $matches[2];
00968                 }
00969                 else
00970                     $this->_redirectaddr = $matches[2];
00971             }
00972         
00973             if(preg_match("|^HTTP/|",$result_headers[$currentHeader]))
00974                 $this->response_code = $result_headers[$currentHeader];
00975 
00976             $this->headers[] = $result_headers[$currentHeader];
00977         }
00978 
00979         // check if there is a a redirect meta tag
00980         
00981         if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]+URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
00982         {
00983             $this->_redirectaddr = $this->_expandlinks($match[1],$URI); 
00984         }
00985 
00986         // have we hit our frame depth and is there frame src to fetch?
00987         if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\">]+)'i",$results,$match))
00988         {
00989             $this->results[] = $results;
00990             for($x=0; $x<count($match[1]); $x++)
00991                 $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host);
00992         }
00993         // have we already fetched framed content?
00994         elseif(is_array($this->results))
00995             $this->results[] = $results;
00996         // no framed content
00997         else
00998             $this->results = $results;
00999 
01000         unlink("/tmp/$headerfile");
01001         
01002         return true;
01003     }

HttpClient::_prepare_post_body formvars,
formfiles
 

定義在 httpclient.class.php 檔案之第 1110 行.

參考 $val.

被參考於 submit().

01111     {
01112         settype($formvars, "array");
01113         settype($formfiles, "array");
01114 
01115         if (count($formvars) == 0 && count($formfiles) == 0)
01116             return;
01117         
01118         switch ($this->_submit_type) {
01119             case "application/x-www-form-urlencoded":
01120                 reset($formvars);
01121                 while(list($key,$val) = each($formvars)) {
01122                     if (is_array($val) || is_object($val)) {
01123                         while (list($cur_key, $cur_val) = each($val)) {
01124                             $postdata .= urlencode($key)."[]=".urlencode($cur_val)."&";
01125                         }
01126                     } else
01127                         $postdata .= urlencode($key)."=".urlencode($val)."&";
01128                 }
01129                 break;
01130 
01131             case "multipart/form-data":
01132                 $this->_mime_boundary = "Snoopy".md5(uniqid(microtime()));
01133                 
01134                 reset($formvars);
01135                 while(list($key,$val) = each($formvars)) {
01136                     if (is_array($val) || is_object($val)) {
01137                         while (list($cur_key, $cur_val) = each($val)) {
01138                             $postdata .= "--".$this->_mime_boundary."\r\n";
01139                             $postdata .= "Content-Disposition: form-data; name=\"$key\[\]\"\r\n\r\n";
01140                             $postdata .= "$cur_val\r\n";
01141                         }
01142                     } else {
01143                         $postdata .= "--".$this->_mime_boundary."\r\n";
01144                         $postdata .= "Content-Disposition: form-data; name=\"$key\"\r\n\r\n";
01145                         $postdata .= "$val\r\n";
01146                     }
01147                 }
01148                 
01149                 reset($formfiles);
01150                 while (list($field_name, $file_names) = each($formfiles)) {
01151                     settype($file_names, "array");
01152                     while (list(, $file_name) = each($file_names)) {
01153                         if (!is_readable($file_name)) continue;
01154 
01155                         $fp = fopen($file_name, "r");
01156                         $file_content = fread($fp, filesize($file_name));
01157                         fclose($fp);
01158                         $base_name = basename($file_name);
01159 
01160                         $postdata .= "--".$this->_mime_boundary."\r\n";
01161                         $postdata .= "Content-Disposition: form-data; name=\"$field_name\"; filename=\"$base_name\"\r\n\r\n";
01162                         $postdata .= "$file_content\r\n";
01163                     }
01164                 }
01165                 $postdata .= "--".$this->_mime_boundary."--\r\n";
01166                 break;
01167         }
01168 
01169         return $postdata;
01170     }

HttpClient::_stripform document  ) 
 

定義在 httpclient.class.php 檔案之第 617 行.

被參考於 fetchform().

00618     {   
00619         preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements);
00620         
00621         // catenate the matches
00622         $match = implode("\r\n",$elements[0]);
00623                 
00624         // return the links
00625         return $match;
00626     }

HttpClient::_striplinks document  ) 
 

定義在 httpclient.class.php 檔案之第 583 行.

參考 $val.

被參考於 fetchlinks(), 及 submitlinks().

00584     {   
00585         preg_match_all("'<\s*a\s+.*href\s*=\s*          # find <a href=
00586                         ([\"\'])?                   # find single or double quote
00587                         (?(1) (.*?)\\1 | ([^\s>]+))     # if quote found, match up to next matching
00588                                                     # quote, otherwise match up to next space
00589                         'isx",$document,$links);
00590                         
00591 
00592         // catenate the non-empty matches from the conditional subpattern
00593 
00594         while(list($key,$val) = each($links[2]))
00595         {
00596             if(!empty($val))
00597                 $match[] = $val;
00598         }               
00599         
00600         while(list($key,$val) = each($links[3]))
00601         {
00602             if(!empty($val))
00603                 $match[] = $val;
00604         }       
00605         
00606         // return the links
00607         return $match;
00608     }

HttpClient::_striptext document  ) 
 

定義在 httpclient.class.php 檔案之第 637 行.

參考 $text.

被參考於 fetchtext().

00638     {
00639         
00640         // I didn't use preg eval (//e) since that is only available in PHP 4.0.
00641         // so, list your entities one by one here. I included some of the
00642         // more common ones.
00643                                 
00644         $search = array("'<script[^>]*?>.*?</script>'si",   // strip out javascript
00645                         "'<[\/\!]*?[^<>]*?>'si",            // strip out html tags
00646                         "'([\r\n])[\s]+'",                  // strip out white space
00647                         "'&(quote|#34);'i",                 // replace html entities
00648                         "'&(amp|#38);'i",
00649                         "'&(lt|#60);'i",
00650                         "'&(gt|#62);'i",
00651                         "'&(nbsp|#160);'i",
00652                         "'&(iexcl|#161);'i",
00653                         "'&(cent|#162);'i",
00654                         "'&(pound|#163);'i",
00655                         "'&(copy|#169);'i"
00656                         );              
00657         $replace = array(   "",
00658                             "",
00659                             "\\1",
00660                             "\"",
00661                             "&",
00662                             "<",
00663                             ">",
00664                             " ",
00665                             chr(161),
00666                             chr(162),
00667                             chr(163),
00668                             chr(169));
00669                     
00670         $text = preg_replace($search,$replace,$document);
00671                                 
00672         return $text;
00673     }

HttpClient::fetch URI  ) 
 

定義在 httpclient.class.php 檔案之第 118 行.

參考 $path, _connect(), _disconnect(), _httprequest(), _httpsrequest(), 及 n.

被參考於 fetchform(), fetchlinks(), fetchtext(), 及 submit().

00119     {
00120     
00121         //preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS);
00122         $URI_PARTS = parse_url($URI);
00123         if (!empty($URI_PARTS["user"]))
00124             $this->user = $URI_PARTS["user"];
00125         if (!empty($URI_PARTS["pass"]))
00126             $this->pass = $URI_PARTS["pass"];
00127                 
00128         switch($URI_PARTS["scheme"])
00129         {
00130             case "http":
00131                 $this->host = $URI_PARTS["host"];
00132                 if(!empty($URI_PARTS["port"]))
00133                     $this->port = $URI_PARTS["port"];
00134                 if($this->_connect($fp))
00135                 {
00136                     if($this->_isproxy)
00137                     {
00138                         // using proxy, send entire URI
00139                         $this->_httprequest($URI,$fp,$URI,$this->_httpmethod);
00140                     }
00141                     else
00142                     {
00143                         $path = $URI_PARTS["path"].(( array_key_exists( "query", $URI_PARTS ) && $URI_PARTS["query"] ) ? "?".$URI_PARTS["query"] : "");
00144                         // no proxy, send only the path
00145                         $this->_httprequest($path, $fp, $URI, $this->_httpmethod);
00146                     }
00147                     
00148                     $this->_disconnect($fp);
00149 
00150                     if($this->_redirectaddr)
00151                     {
00152                         /* url was redirected, check if we've hit the max depth */
00153                         if($this->maxredirs > $this->_redirectdepth)
00154                         {
00155                             // only follow redirect if it's on this site, or offsiteok is true
00156                             if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
00157                             {
00158                                 /* follow the redirect */
00159                                 $this->_redirectdepth++;
00160                                 $this->lastredirectaddr=$this->_redirectaddr;
00161                                 $this->fetch($this->_redirectaddr);
00162                             }
00163                         }
00164                     }
00165 
00166                     if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
00167                     {
00168                         $frameurls = $this->_frameurls;
00169                         $this->_frameurls = array();
00170                         
00171                         while(list(,$frameurl) = each($frameurls))
00172                         {
00173                             if($this->_framedepth < $this->maxframes)
00174                             {
00175                                 $this->fetch($frameurl);
00176                                 $this->_framedepth++;
00177                             }
00178                             else
00179                                 break;
00180                         }
00181                     }                   
00182                 }
00183                 else
00184                 {
00185                     return false;
00186                 }
00187                 return true;                    
00188                 break;
00189             case "https":
00190                 if(!$this->curl_path || (!is_executable($this->curl_path)))
00191                     return false;
00192                 $this->host = $URI_PARTS["host"];
00193                 if(!empty($URI_PARTS["port"]))
00194                     $this->port = $URI_PARTS["port"];
00195                 if($this->_isproxy)
00196                 {
00197                     // using proxy, send entire URI
00198                     $this->_httpsrequest($URI,$URI,$this->_httpmethod);
00199                 }
00200                 else
00201                 {
00202                     $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : "");
00203                     // no proxy, send only the path
00204                     $this->_httpsrequest($path, $URI, $this->_httpmethod);
00205                 }
00206 
00207                 if($this->_redirectaddr)
00208                 {
00209                     /* url was redirected, check if we've hit the max depth */
00210                     if($this->maxredirs > $this->_redirectdepth)
00211                     {
00212                         // only follow redirect if it's on this site, or offsiteok is true
00213                         if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
00214                         {
00215                             /* follow the redirect */
00216                             $this->_redirectdepth++;
00217                             $this->lastredirectaddr=$this->_redirectaddr;
00218                             $this->fetch($this->_redirectaddr);
00219                         }
00220                     }
00221                 }
00222 
00223                 if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
00224                 {
00225                     $frameurls = $this->_frameurls;
00226                     $this->_frameurls = array();
00227 
00228                     while(list(,$frameurl) = each($frameurls))
00229                     {
00230                         if($this->_framedepth < $this->maxframes)
00231                         {
00232                             $this->fetch($frameurl);
00233                             $this->_framedepth++;
00234                         }
00235                         else
00236                             break;
00237                     }
00238                 }                   
00239                 return true;                    
00240                 break;
00241             default:
00242                 // not a valid protocol
00243                 $this->error    =   'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
00244                 return false;
00245                 break;
00246         }       
00247         return true;
00248     }

HttpClient::fetchform URI  ) 
 

定義在 httpclient.class.php 檔案之第 436 行.

參考 _stripform(), 及 fetch().

00437     {
00438         
00439         if ($this->fetch($URI))
00440         {           
00441 
00442             if(is_array($this->results))
00443             {
00444                 for($x=0;$x<count($this->results);$x++)
00445                     $this->results[$x] = $this->_stripform($this->results[$x]);
00446             }
00447             else
00448                 $this->results = $this->_stripform($this->results);
00449             
00450             return true;
00451         }
00452         else
00453             return false;
00454     }

HttpClient::fetchlinks URI  ) 
 

定義在 httpclient.class.php 檔案之第 408 行.

參考 _expandlinks(), _striplinks(), 及 fetch().

00409     {
00410         if ($this->fetch($URI))
00411         {           
00412 
00413             if(is_array($this->results))
00414             {
00415                 for($x=0;$x<count($this->results);$x++)
00416                     $this->results[$x] = $this->_striplinks($this->results[$x]);
00417             }
00418             else
00419                 $this->results = $this->_striplinks($this->results);
00420 
00421             if($this->expandlinks)
00422                 $this->results = $this->_expandlinks($this->results, $URI);
00423             return true;
00424         }
00425         else
00426             return false;
00427     }

HttpClient::fetchtext URI  ) 
 

定義在 httpclient.class.php 檔案之第 464 行.

參考 _striptext(), 及 fetch().

00465     {
00466         if($this->fetch($URI))
00467         {           
00468             if(is_array($this->results))
00469             {
00470                 for($x=0;$x<count($this->results);$x++)
00471                     $this->results[$x] = $this->_striptext($this->results[$x]);
00472             }
00473             else
00474                 $this->results = $this->_striptext($this->results);
00475             return true;
00476         }
00477         else
00478             return false;
00479     }

HttpClient::set_submit_multipart  ) 
 

定義在 httpclient.class.php 檔案之第 552 行.

00553     {
00554         $this->_submit_type = "multipart/form-data";
00555     }

HttpClient::set_submit_normal  ) 
 

定義在 httpclient.class.php 檔案之第 563 行.

00564     {
00565         $this->_submit_type = "application/x-www-form-urlencoded";
00566     }

HttpClient::setcookies  ) 
 

定義在 httpclient.class.php 檔案之第 1010 行.

01011     {
01012         for($x=0; $x<count($this->headers); $x++)
01013         {
01014         if(preg_match("/^set-cookie:[\s]+([^=]+)=([^;]+)/i", $this->headers[$x],$match))
01015             $this->cookies[$match[1]] = $match[2];
01016         }
01017     }

HttpClient::submit URI,
formvars = "",
formfiles = ""
 

定義在 httpclient.class.php 檔案之第 259 行.

參考 $path, _connect(), _disconnect(), _expandlinks(), _httprequest(), _httpsrequest(), _prepare_post_body(), fetch(), 及 n.

被參考於 submitlinks().

00260     {
00261         unset($postdata);
00262         
00263         $postdata = $this->_prepare_post_body($formvars, $formfiles);
00264             
00265         $URI_PARTS = parse_url($URI);
00266         if (!empty($URI_PARTS["user"]))
00267             $this->user = $URI_PARTS["user"];
00268         if (!empty($URI_PARTS["pass"]))
00269             $this->pass = $URI_PARTS["pass"];
00270                 
00271         switch($URI_PARTS["scheme"])
00272         {
00273             case "http":
00274                 $this->host = $URI_PARTS["host"];
00275                 if(!empty($URI_PARTS["port"]))
00276                     $this->port = $URI_PARTS["port"];
00277                 if($this->_connect($fp))
00278                 {
00279                     if($this->_isproxy)
00280                     {
00281                         // using proxy, send entire URI
00282                         $this->_httprequest($URI,$fp,$URI,$this->_submit_method,$this->_submit_type,$postdata);
00283                     }
00284                     else
00285                     {
00286                         $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : "");
00287                         // no proxy, send only the path
00288                         $this->_httprequest($path, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata);
00289                     }
00290                     
00291                     $this->_disconnect($fp);
00292 
00293                     if($this->_redirectaddr)
00294                     {
00295                         /* url was redirected, check if we've hit the max depth */
00296                         if($this->maxredirs > $this->_redirectdepth)
00297                         {                       
00298                             if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
00299                                 $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);                     
00300                             
00301                             // only follow redirect if it's on this site, or offsiteok is true
00302                             if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
00303                             {
00304                                 /* follow the redirect */
00305                                 $this->_redirectdepth++;
00306                                 $this->lastredirectaddr=$this->_redirectaddr;
00307                                 $this->submit($this->_redirectaddr,$formvars, $formfiles);
00308                             }
00309                         }
00310                     }
00311 
00312                     if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
00313                     {
00314                         $frameurls = $this->_frameurls;
00315                         $this->_frameurls = array();
00316                         
00317                         while(list(,$frameurl) = each($frameurls))
00318                         {                                                       
00319                             if($this->_framedepth < $this->maxframes)
00320                             {
00321                                 $this->fetch($frameurl);
00322                                 $this->_framedepth++;
00323                             }
00324                             else
00325                                 break;
00326                         }
00327                     }                   
00328                     
00329                 }
00330                 else
00331                 {
00332                     return false;
00333                 }
00334                 return true;                    
0033