ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilHttpRequest Class Reference

ilHttpRequest class More...

+ Collaboration diagram for ilHttpRequest:

Public Member Functions

 _scan_url ()
 
 __construct ($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.

Constructor & Destructor Documentation

◆ __construct()

ilHttpRequest::__construct (   $url)

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

72 {
73 $this->_url = $url;
74 $this->_scan_url();
75 }
$url

References $url, and _scan_url().

+ Here is the call graph for this function:

Member Function Documentation

◆ _scan_url()

ilHttpRequest::_scan_url ( )

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

44 {
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) {
53 $pos = strlen($req);
54 }
55 $host = substr($req, 0, $pos);
56
57 if (strpos($host, ':') !== false) {
58 list($this->_host, $this->_port) = explode(':', $host);
59 } else {
60 $this->_host = $host;
61 $this->_port = ($this->_protocol == 'https') ? 443 : 80;
62 }
63
64 $this->_uri = substr($req, $pos);
65 if ($this->_uri == '') {
66 $this->_uri = '/';
67 }
68 }
$req
Definition: getUserInfo.php:20

References $_url, and $req.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ downloadToString()

ilHttpRequest::downloadToString ( )

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

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

References $header, $http, $req, and $response.

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: