ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilHttpRequest Class Reference

ilHttpRequest class More...

+ Collaboration diagram for ilHttpRequest:

Public Member Functions

 _scan_url ()
 
 ilHttpRequest ($url)
 
 downloadToString ()
 

Data Fields

 $_fp
 
 $_url
 
 $_host
 
 $_protocol
 
 $_uri
 
 $_port
 

Detailed Description

ilHttpRequest class

Class to retrieve an HTTP request

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$

Definition at line 33 of file class.ilHttpRequest.php.

Member Function Documentation

◆ _scan_url()

ilHttpRequest::_scan_url ( )

Definition at line 43 of file class.ilHttpRequest.php.

44 {
45 $req = $this->_url;
46
47 $pos = strpos($req, '://');
48 $this->_protocol = strtolower(substr($req, 0, $pos));
49
50 $req = substr($req, $pos+3);
51 $pos = strpos($req, '/');
52 if($pos === false) $pos = strlen($req);
53 $host = substr($req, 0, $pos);
54
55 if(strpos($host, ':') !== false)
56 {
57 list($this->_host, $this->_port) = explode(':', $host);
58 }
59 else
60 {
61 $this->_host = $host;
62 $this->_port = ($this->_protocol == 'https') ? 443 : 80;
63 }
64
65 $this->_uri = substr($req, $pos);
66 if($this->_uri == '') $this->_uri = '/';
67 }

References $_url.

Referenced by ilHttpRequest().

+ Here is the caller graph for this function:

◆ downloadToString()

ilHttpRequest::downloadToString ( )

Definition at line 77 of file class.ilHttpRequest.php.

78 {
79 $crlf = "\r\n";
80
81 // generate request
82 $req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf
83 . 'Host: ' . $this->_host . $crlf
84 . $crlf;
85
86 // fetch
87 $this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
88 fwrite($this->_fp, $req);
89 while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp))
90 {
91 $response .= fread($this->_fp, 1024);
92 }
93 fclose($this->_fp);
94
95 // split header and body
96 $pos = strpos($response, $crlf . $crlf);
97 if($pos === false) return($response);
98 $header = substr($response, 0, $pos);
99 $body = substr($response, $pos + 2 * strlen($crlf));
100
101 // parse headers
102 $headers = array();
103 $lines = explode($crlf, $header);
104 foreach($lines as $line)
105 {
106 if(($pos = strpos($line, ':')) !== false)
107 {
108 $headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1));
109 }
110 }
111
112 // redirection?
113 if(isset($headers['location']))
114 {
115 $http = new ilHttpRequest($headers['location']);
116 return($http->DownloadToString($http));
117 }
118 else
119 {
120 return($body);
121 }
122 }
$header

References $header, and ilHttpRequest().

+ Here is the call graph for this function:

◆ ilHttpRequest()

ilHttpRequest::ilHttpRequest (   $url)

Definition at line 70 of file class.ilHttpRequest.php.

71 {
72 $this->_url = $url;
73 $this->_scan_url();
74 }
$url
Definition: shib_logout.php:72

References $url, and _scan_url().

Referenced by downloadToString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $_fp

ilHttpRequest::$_fp

Definition at line 35 of file class.ilHttpRequest.php.

◆ $_host

ilHttpRequest::$_host

Definition at line 37 of file class.ilHttpRequest.php.

◆ $_port

ilHttpRequest::$_port

Definition at line 40 of file class.ilHttpRequest.php.

◆ $_protocol

ilHttpRequest::$_protocol

Definition at line 38 of file class.ilHttpRequest.php.

◆ $_uri

ilHttpRequest::$_uri

Definition at line 39 of file class.ilHttpRequest.php.

◆ $_url

ilHttpRequest::$_url

Definition at line 36 of file class.ilHttpRequest.php.

Referenced by _scan_url().


The documentation for this class was generated from the following file: