eba8d60cefc2c3838f84a949e2bda4c8ef4c3c6c
[m6w6/ext-http] / docs / functions.html
1 <html>
2 <head><title>Function Summary</title>
3 <style>body { font-size: 80%; font-family: sans-serif; } h2 { color: #339; } pre { font-size: 1.2em; } </style></head>
4 <body>
5 <h1>http.c</h1>
6 <h2>void HTTPi_Response::__construct(bool cache, bool gzip)</h2>
7 <p></p>
8 <h2>bool HTTPi_Response::setCache(bool cache)</h2>
9 <p></p>
10 <h2>bool HTTPi_Response::getCache()</h2>
11 <p></p>
12 <h2>bool HTTPi_Response::setGzip(bool gzip)</h2>
13 <p></p>
14 <h2>bool HTTPi_Response::getGzip()</h2>
15 <p></p>
16 <h2>bool HTTPi_Response::setCacheControl(string control[, bool raw = false])</h2>
17 <p></p>
18 <h2>string HTTPi_Response::getCacheControl()</h2>
19 <p></p>
20 <h2>bool HTTPi::setContentType(string content_type)</h2>
21 <p></p>
22 <h2>string HTTPi_Response::getContentType()</h2>
23 <p></p>
24 <h2>bool HTTPi_Response::setContentDisposition(string filename[, bool inline = false])</h2>
25 <p></p>
26 <h2>array HTTPi_Response::getContentDisposition()</h2>
27 <p></p>
28 <h2>bool HTTPi_Response::setETag(string etag)</h2>
29 <p></p>
30 <h2>string HTTPi_Response::getETag()</h2>
31 <p></p>
32 <h2>bool HTTPi_Response::setData(string data)</h2>
33 <p></p>
34 <h2>string HTTPi_Response::getData()</h2>
35 <p></p>
36 <h2>bool HTTPi_Response::setStream(resource stream)</h2>
37 <p></p>
38 <h2>resource HTTPi_Response::getStream()</h2>
39 <p></p>
40 <h2>bool HTTPi_Response::setFile(string file)</h2>
41 <p></p>
42 <h2>string HTTPi_Response::getFile()</h2>
43 <p></p>
44 <h2>int HTTPi_Response::getSize()</h2>
45 <p></p>
46 <h2>string http_date([int timestamp])</h2>
47 <p>This function returns a valid HTTP date regarding RFC 822/1123
48 looking like: "Wed, 22 Dec 2004 11:34:47 GMT"</p>
49 <h2>string http_absolute_uri(string url[, string proto])</h2>
50 <p>This function returns an absolute URI constructed from url.
51 If the url is already abolute but a different proto was supplied,
52 only the proto part of the URI will be updated. If url has no
53 path specified, the path of the current REQUEST_URI will be taken.
54 The host will be taken either from the Host HTTP header of the client
55 the SERVER_NAME or just localhost if prior are not available.</p><p>Some examples:
56 <pre>
57 url = "page.php" => http://www.example.com/current/path/page.php
58 url = "/page.php" => http://www.example.com/page.php
59 url = "/page.php", proto = "https" => https://www.example.com/page.php
60 </pre></p>
61 <h2>string http_negotiate_language(array supported[, string default = 'en-US'])</h2>
62 <p>This function negotiates the clients preferred language based on its
63 Accept-Language HTTP header. It returns the negotiated language or
64 the default language if none match.</p><p>The qualifier is recognized and languages without qualifier are rated highest.</p><p>The supported parameter is expected to be an array having
65 the supported languages as array values.</p><p>Example:
66 <pre>
67 <code><span style="color: #000000">
68 <span style="color: #0000BB">&lt;?php<br />$langs </span><span style="color: #007700">= array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'en-US'</span><span style="color: #007700">,</span><span style="color: #FF8000">// default<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'fr'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'fr-FR'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-DE'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-AT'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-CH'</span><span style="color: #007700">,<br />);<br />include </span><span style="color: #DD0000">'./langs/'</span><span style="color: #007700">. </span><span style="color: #0000BB">http_negotiate_language</span><span style="color: #007700">(</span><span style="color: #0000BB">$langs</span><span style="color: #007700">) .</span><span style="color: #DD0000">'.php'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
69 </span>
70 </code>
71 </pre></p>
72 <h2>string http_negotiate_charset(array supported[, string default = 'iso-8859-1'])</h2>
73 <p>This function negotiates the clients preferred charset based on its
74 Accept-Charset HTTP header. It returns the negotiated charset or
75 the default charset if none match.</p><p>The qualifier is recognized and charset without qualifier are rated highest.</p><p>The supported parameter is expected to be an array having
76 the supported charsets as array values.</p><p>Example:
77 <pre>
78 <code><span style="color: #000000">
79 <span style="color: #0000BB">&lt;?php<br />$charsets </span><span style="color: #007700">= array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'iso-8859-1'</span><span style="color: #007700">, </span><span style="color: #FF8000">// default<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'iso-8859-2'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'iso-8859-15'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'utf-8'<br /></span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$pref </span><span style="color: #007700">= </span><span style="color: #0000BB">http_negotiate_charset</span><span style="color: #007700">(</span><span style="color: #0000BB">$charsets</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">strcmp</span><span style="color: #007700">(</span><span style="color: #0000BB">$pref</span><span style="color: #007700">, </span><span style="color: #DD0000">'iso-8859-1'</span><span style="color: #007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">iconv_set_encoding</span><span style="color: #007700">(</span><span style="color: #DD0000">'internal_encoding'</span><span style="color: #007700">, </span><span style="color: #DD0000">'iso-8859-1'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">iconv_set_encoding</span><span style="color: #007700">(</span><span style="color: #DD0000">'output_encoding'</span><span style="color: #007700">, </span><span style="color: #0000BB">$pref</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">ob_start</span><span style="color: #007700">(</span><span style="color: #DD0000">'ob_iconv_handler'</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
80 </span>
81 </code>
82 </pre></p>
83 <h2>bool http_send_status(int status)</h2>
84 <p>Send HTTP status code.</p>
85 <h2>bool http_send_last_modified([int timestamp])</h2>
86 <p>This converts the given timestamp to a valid HTTP date and
87 sends it as "Last-Modified" HTTP header. If timestamp is
88 omitted, current time is sent.</p>
89 <h2>bool http_match_modified([int timestamp])</h2>
90 <p>Matches the given timestamp against the clients "If-Modified-Since" resp.
91 "If-Unmodified-Since" HTTP headers.</p>
92 <h2>bool http_match_etag(string etag)</h2>
93 <p>This matches the given ETag against the clients
94 "If-Match" resp. "If-None-Match" HTTP headers.</p>
95 <h2>bool http_cache_last_modified([int timestamp_or_expires]])</h2>
96 <p>If timestamp_or_exires is greater than 0, it is handled as timestamp
97 and will be sent as date of last modification. If it is 0 or omitted,
98 the current time will be sent as Last-Modified date. If it's negative,
99 it is handled as expiration time in seconds, which means that if the
100 requested last modification date is not between the calculated timespan,
101 the Last-Modified header is updated and the actual body will be sent.</p>
102 <h2>bool http_cache_etag([string etag])</h2>
103 <p>This function attempts to cache the HTTP body based on an ETag,
104 either supplied or generated through calculation of the MD5
105 checksum of the output (uses output buffering).</p><p>If clients "If-None-Match" header matches the supplied/calculated
106 ETag, the body is considered cached on the clients side and
107 a "304 Not Modified" status code is issued.</p>
108 <h2>string ob_httpetaghandler(string data, int mode)</h2>
109 <p>For use with ob_start().
110 Note that this has to be started as first output buffer.
111 WARNING: Don't use with http_send_*().</p>
112 <h2>void http_redirect([string url[, array params[, bool session,[ bool permanent]]]])</h2>
113 <p>Redirect to a given url.
114 The supplied url will be expanded with http_absolute_uri(), the params array will
115 be treated with http_build_query() and the session identification will be appended
116 if session is true.</p><p>Depending on permanent the redirection will be issued with a permanent
117 ("301 Moved Permanently") or a temporary ("302 Found") redirection
118 status code.</p><p>To be RFC compliant, "Redirecting to <a>URI</a>." will be displayed,
119 if the client doesn't redirect immediatly.</p>
120 <h2>bool http_send_data(string data)</h2>
121 <p>Sends raw data with support for (multiple) range requests.</p>
122 <h2>bool http_send_file(string file)</h2>
123 <p>Sends a file with support for (multiple) range requests.</p>
124 <h2>bool http_send_stream(resource stream)</h2>
125 <p>Sends an already opened stream with support for (multiple) range requests.</p>
126 <h2>bool http_content_type([string content_type = 'application/x-octetstream'])</h2>
127 <p>Sets the content type.</p>
128 <h2>bool http_content_disposition(string filename[, bool inline = false])</h2>
129 <p>Set the Content Disposition. The Content-Disposition header is very useful
130 if the data actually sent came from a file or something similar, that should
131 be "saved" by the client/user (i.e. by browsers "Save as..." popup window).</p>
132 <h2>string http_chunked_decode(string encoded)</h2>
133 <p>This function decodes a string that was HTTP-chunked encoded.
134 Returns false on failure.</p>
135 <h2>array http_split_response(string http_response)</h2>
136 <p>This function splits an HTTP response into an array with headers and the
137 content body. The returned array may look simliar to the following example:</p><p><pre>
138 <code><span style="color: #000000">
139 <span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">array(<br /></span><span style="color: #0000BB">0 </span><span style="color: #007700">=&gt; array(<br /></span><span style="color: #DD0000">'Status' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'200 Ok'</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'Content-Type' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/plain'</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'Content-Language' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'en-US'<br /></span><span style="color: #007700">),<br /></span><span style="color: #0000BB">1 </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"Hello World!\"<br />);<br />?&gt;</span>
140 </span>
141 </code>
142 </pre></p>
143 <h2>array http_parse_headers(string header)</h2>
144 <p></p>
145 <h2>array http_get_request_headers(void)</h2>
146 <p></p>
147 <h2>string http_get(string url[, array options[, array &info]])</h2>
148 <p>Performs an HTTP GET request on the supplied url.</p><p>The second parameter is expected to be an associative
149 array where the following keys will be recognized:
150 <pre>
151 - redirect: int, whether and how many redirects to follow
152 - unrestrictedauth: bool, whether to continue sending credentials on
153 redirects to a different host
154 - proxyhost: string, proxy host in "host[:port]" format
155 - proxyport: int, use another proxy port as specified in proxyhost
156 - proxyauth: string, proxy credentials in "user:pass" format
157 - proxyauthtype: int, HTTP_AUTH_BASIC and/or HTTP_AUTH_NTLM
158 - httpauth: string, http credentials in "user:pass" format
159 - httpauthtype: int, HTTP_AUTH_BASIC, DIGEST and/or NTLM
160 - compress: bool, whether to allow gzip/deflate content encoding
161 (defaults to true)
162 - port: int, use another port as specified in the url
163 - referer: string, the referer to sends
164 - useragent: string, the user agent to send
165 (defaults to PECL::HTTP/version (PHP/version)))
166 - headers: array, list of custom headers as associative array
167 like array("header" => "value")
168 - cookies: array, list of cookies as associative array
169 like array("cookie" => "value")
170 - cookiestore: string, path to a file where cookies are/will be stored
171 </pre></p><p>The optional third parameter will be filled with some additional information
172 in form af an associative array, if supplied, like the following example:
173 <pre>
174 <code><span style="color: #000000">
175 <span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">array (<br /></span><span style="color: #DD0000">'effective_url' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'http://localhost'</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'response_code' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">403</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'total_time' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">0.017</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'namelookup_time' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">0.013</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'connect_time' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">0.014</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'pretransfer_time' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">0.014</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'size_upload' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'size_download' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">202</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'speed_download' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">11882</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'speed_upload' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'header_size' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">145</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'request_size' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">62</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'ssl_verifyresult' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'filetime' </span><span style="color: #007700">=&gt; -</span><span style="color: #0000BB">1</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'content_length_download' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">202</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'content_length_upload' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'starttransfer_time' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">0.017</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'content_type' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'text/html; charset=iso-8859-1'</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'redirect_time' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'redirect_count' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'private' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'http_connectcode' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'httpauth_avail' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">'proxyauth_avail' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">,<br />)<br /></span><span style="color: #0000BB">?&gt;</span>
176 </span>
177 </code>
178 </pre></p>
179 <h2>string http_head(string url[, array options[, array &info]])</h2>
180 <p>Performs an HTTP HEAD request on the suppied url.
181 Returns the HTTP response as string.
182 See http_get() for a full list of available options.</p>
183 <h2>string http_post_data(string url, string data[, array options[, &info]])</h2>
184 <p>Performs an HTTP POST request, posting data.
185 Returns the HTTP response as string.
186 See http_get() for a full list of available options.</p>
187 <h2>string http_post_array(string url, array data[, array options[, array &info]])</h2>
188 <p>Performs an HTTP POST request, posting www-form-urlencoded array data.
189 Returns the HTTP response as string.
190 See http_get() for a full list of available options.</p>
191 <h2>bool http_auth_basic(string user, string pass[, string realm = "Restricted"])</h2>
192 <p>Example:
193 <pre>
194 <code><span style="color: #000000">
195 <span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">http_auth_basic</span><span style="color: #007700">(</span><span style="color: #DD0000">'mike'</span><span style="color: #007700">, </span><span style="color: #DD0000">'s3c|r3t'</span><span style="color: #007700">)) {<br />die(</span><span style="color: #DD0000">'&lt;h1&gt;Authorization failed!&lt;/h1&gt;'</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
196 </span>
197 </code>
198 </pre></p>
199 <h2>bool http_auth_basic_cb(mixed callback[, string realm = "Restricted"])</h2>
200 <p>Example:
201 <pre>
202 <code><span style="color: #000000">
203 <span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">auth_cb</span><span style="color: #007700">(</span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$pass</span><span style="color: #007700">)<br />{<br />global </span><span style="color: #0000BB">$db</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #DD0000">'SELECT pass FROM users WHERE user='</span><span style="color: #007700">. </span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">quoteSmart</span><span style="color: #007700">(</span><span style="color: #0000BB">$user</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$realpass </span><span style="color: #007700">= </span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getOne</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">)) {<br />return </span><span style="color: #0000BB">$pass </span><span style="color: #007700">=== </span><span style="color: #0000BB">$realpass</span><span style="color: #007700">;<br />}<br />return </span><span style="color: #0000BB">false</span><span style="color: #007700">;<br />}<br /><br />if (!</span><span style="color: #0000BB">http_auth_basic_cb</span><span style="color: #007700">(</span><span style="color: #DD0000">'auth_cb'</span><span style="color: #007700">)) {<br />die(</span><span style="color: #DD0000">'&lt;h1&gt;Authorization failed&lt;/h1&gt;'</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
204 </span>
205 </code>
206 </pre></p>
207 <hr noshade><p><b> Generated at: Thu, 17 Feb 2005 22:42:18 +0100</b></p>
208 </body>
209 </html>