Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00033 class ilHttpRequest
00034 {
00035 var $_fp;
00036 var $_url;
00037 var $_host;
00038 var $_protocol;
00039 var $_uri;
00040 var $_port;
00041
00042
00043 function _scan_url()
00044 {
00045 $req = $this->_url;
00046
00047 $pos = strpos($req, '://');
00048 $this->_protocol = strtolower(substr($req, 0, $pos));
00049
00050 $req = substr($req, $pos+3);
00051 $pos = strpos($req, '/');
00052 if($pos === false) $pos = strlen($req);
00053 $host = substr($req, 0, $pos);
00054
00055 if(strpos($host, ':') !== false)
00056 {
00057 list($this->_host, $this->_port) = explode(':', $host);
00058 }
00059 else
00060 {
00061 $this->_host = $host;
00062 $this->_port = ($this->_protocol == 'https') ? 443 : 80;
00063 }
00064
00065 $this->_uri = substr($req, $pos);
00066 if($this->_uri == '') $this->_uri = '/';
00067 }
00068
00069
00070 function ilHttpRequest($url)
00071 {
00072 $this->_url = $url;
00073 $this->_scan_url();
00074 }
00075
00076
00077 function downloadToString()
00078 {
00079 $crlf = "\r\n";
00080
00081
00082 $req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf
00083 . 'Host: ' . $this->_host . $crlf
00084 . $crlf;
00085
00086
00087 $this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
00088 fwrite($this->_fp, $req);
00089 while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp))
00090 {
00091 $response .= fread($this->_fp, 1024);
00092 }
00093 fclose($this->_fp);
00094
00095
00096 $pos = strpos($response, $crlf . $crlf);
00097 if($pos === false) return($response);
00098 $header = substr($response, 0, $pos);
00099 $body = substr($response, $pos + 2 * strlen($crlf));
00100
00101
00102 $headers = array();
00103 $lines = explode($crlf, $header);
00104 foreach($lines as $line)
00105 {
00106 if(($pos = strpos($line, ':')) !== false)
00107 {
00108 $headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1));
00109 }
00110 }
00111
00112
00113 if(isset($headers['location']))
00114 {
00115 $http = new ilHttpRequest($headers['location']);
00116 return($http->DownloadToString($http));
00117 }
00118 else
00119 {
00120 return($body);
00121 }
00122 }
00123 }
00124 ?>