4c6ff04d2811160a889484a4d473818310061dd9
[m6w6/ext-http] / docs / functions.html
1 <html>
2 <head>
3 <title>Function Summary of ext/http</title>
4 <style>
5 body {
6 font-size: 80%;
7 font-family: sans-serif;
8 }
9 h2, h3 {
10 color: #339;
11 clear: both;
12 font-size: 1.2em;
13 background: #ffc;
14 padding: .2em;
15 }
16 h2.o {
17 color: #66b;
18 clear: both;
19 font-size: 1.3em;
20 background: #f0f0f0;
21 padding: .2em;
22 }
23 p {
24 margin-left: 1em;
25 }
26 pre {
27 font-size: 1.2em;
28 }
29 br {
30 display: none;
31 }
32 blockquote {
33 margin-bottom: 3em;
34 border: 1px solid #ccc;
35 background: #f0f0f0;
36 padding: 0em 1em;
37 width: auto;
38 float: left;
39 }
40 p, pre {
41 clear: both;
42 }
43 p br, pre code br {
44 display: block;
45 }
46 </style>
47 </head>
48 <body><h1>http_functions.c</h1>
49 <h2 id="http_date">string http_date([int timestamp])</h2>
50 <p>This function returns a valid HTTP date regarding RFC 822/1123<br />
51 looking like: "Wed, 22 Dec 2004 11:34:47 GMT"</p>
52 <h2 id="http_absolute_uri">string http_absolute_uri(string url[, string proto[, string host[, int port]]])</h2>
53 <p>This function returns an absolute URI constructed from url.<br />
54 If the url is already abolute but a different proto was supplied,<br />
55 only the proto part of the URI will be updated. If url has no<br />
56 path specified, the path of the current REQUEST_URI will be taken.<br />
57 The host will be taken either from the Host HTTP header of the client<br />
58 the SERVER_NAME or just localhost if prior are not available.<br />
59 <br />
60 Some examples:</p><pre> url = "page.php" => http://www.example.com/current/path/page.php<br />
61 url = "/page.php" => http://www.example.com/page.php<br />
62 url = "/page.php", proto = "https" => https://www.example.com/page.php<br />
63 </pre></p>
64 <h2 id="http_negotiate_language">string http_negotiate_language(array supported[, string default = 'en-US'])</h2>
65 <p>This function negotiates the clients preferred language based on its<br />
66 Accept-Language HTTP header. It returns the negotiated language or<br />
67 the default language if none match.<br />
68 <br />
69 The qualifier is recognized and languages without qualifier are rated highest.<br />
70 <br />
71 The supported parameter is expected to be an array having<br />
72 the supported languages as array values.<br />
73 <br />
74 Example:</p><pre><blockquote><code><font color="#000000"><br />
75 <font color="#0000BB">&lt;?php<br />$langs </font><font color="#007700">= array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'en-US'</font><font color="#007700">,</font><font color="#FF8000">// default<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'fr'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'fr-FR'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'de'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'de-DE'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'de-AT'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'de-CH'</font><font color="#007700">,<br />);<br />include </font><font color="#DD0000">'./langs/'</font><font color="#007700">. </font><font color="#0000BB">http_negotiate_language</font><font color="#007700">(</font><font color="#0000BB">$langs</font><font color="#007700">) .</font><font color="#DD0000">'.php'</font><font color="#007700">;<br /></font><font color="#0000BB">?&gt;</font><br />
76 </font><br />
77 </code></blockquote><br />
78 <br />
79 </pre></p>
80 <h2 id="http_negotiate_charset">string http_negotiate_charset(array supported[, string default = 'iso-8859-1'])</h2>
81 <p>This function negotiates the clients preferred charset based on its<br />
82 Accept-Charset HTTP header. It returns the negotiated charset or<br />
83 the default charset if none match.<br />
84 <br />
85 The qualifier is recognized and charset without qualifier are rated highest.<br />
86 <br />
87 The supported parameter is expected to be an array having<br />
88 the supported charsets as array values.<br />
89 <br />
90 Example:</p><pre><blockquote><code><font color="#000000"><br />
91 <font color="#0000BB">&lt;?php<br />$charsets </font><font color="#007700">= array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'iso-8859-1'</font><font color="#007700">, </font><font color="#FF8000">// default<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'iso-8859-2'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'iso-8859-15'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'utf-8'<br /></font><font color="#007700">);<br /></font><font color="#0000BB">$pref </font><font color="#007700">= </font><font color="#0000BB">http_negotiate_charset</font><font color="#007700">(</font><font color="#0000BB">$charsets</font><font color="#007700">);<br />if (!</font><font color="#0000BB">strcmp</font><font color="#007700">(</font><font color="#0000BB">$pref</font><font color="#007700">, </font><font color="#DD0000">'iso-8859-1'</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">iconv_set_encoding</font><font color="#007700">(</font><font color="#DD0000">'internal_encoding'</font><font color="#007700">, </font><font color="#DD0000">'iso-8859-1'</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">iconv_set_encoding</font><font color="#007700">(</font><font color="#DD0000">'output_encoding'</font><font color="#007700">, </font><font color="#0000BB">$pref</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">ob_start</font><font color="#007700">(</font><font color="#DD0000">'ob_iconv_handler'</font><font color="#007700">);<br />}<br /></font><font color="#0000BB">?&gt;</font><br />
92 </font><br />
93 </code></blockquote><br />
94 <br />
95 </pre></p>
96 <h2 id="http_send_status">bool http_send_status(int status)</h2>
97 <p>Send HTTP status code.</p>
98 <h2 id="http_send_last_modified">bool http_send_last_modified([int timestamp])</h2>
99 <p>This converts the given timestamp to a valid HTTP date and<br />
100 sends it as "Last-Modified" HTTP header. If timestamp is<br />
101 omitted, current time is sent.</p>
102 <h2 id="http_send_content_type">bool http_send_content_type([string content_type = 'application/x-octetstream'])</h2>
103 <p>Sets the content type.</p>
104 <h2 id="http_send_content_disposition">bool http_send_content_disposition(string filename[, bool inline = false])</h2>
105 <p>Set the Content Disposition. The Content-Disposition header is very useful<br />
106 if the data actually sent came from a file or something similar, that should<br />
107 be "saved" by the client/user (i.e. by browsers "Save as..." popup window).</p>
108 <h2 id="http_match_modified">bool http_match_modified([int timestamp[, for_range = false]])</h2>
109 <p>Matches the given timestamp against the clients "If-Modified-Since" resp.<br />
110 "If-Unmodified-Since" HTTP headers.</p>
111 <h2 id="http_match_etag">bool http_match_etag(string etag[, for_range = false])</h2>
112 <p>This matches the given ETag against the clients<br />
113 "If-Match" resp. "If-None-Match" HTTP headers.</p>
114 <h2 id="http_cache_last_modified">bool http_cache_last_modified([int timestamp_or_expires]])</h2>
115 <p>If timestamp_or_expires is greater than 0, it is handled as timestamp<br />
116 and will be sent as date of last modification. If it is 0 or omitted,<br />
117 the current time will be sent as Last-Modified date. If it's negative,<br />
118 it is handled as expiration time in seconds, which means that if the<br />
119 requested last modification date is not between the calculated timespan,<br />
120 the Last-Modified header is updated and the actual body will be sent.</p>
121 <h2 id="http_cache_etag">bool http_cache_etag([string etag])</h2>
122 <p>This function attempts to cache the HTTP body based on an ETag,<br />
123 either supplied or generated through calculation of the MD5<br />
124 checksum of the output (uses output buffering).<br />
125 <br />
126 If clients "If-None-Match" header matches the supplied/calculated<br />
127 ETag, the body is considered cached on the clients side and<br />
128 a "304 Not Modified" status code is issued.</p>
129 <h2 id="ob_etaghandler">string ob_etaghandler(string data, int mode)</h2>
130 <p>For use with ob_start().</p>
131 <h2 id="http_throttle">void http_throttle(double sec[, long bytes = 2097152])</h2>
132 <p>Use with http_send() API.<br />
133 <br />
134 Example:</p><pre><blockquote><code><font color="#000000"><br />
135 <font color="#0000BB">&lt;?php<br /></font><font color="#FF8000">// ~ 20 kbyte/s<br /># http_throttle(1, 20000);<br /># http_throttle(0.5, 10000);<br /># http_throttle(0.1, 2000);<br /></font><font color="#0000BB">http_send_file</font><font color="#007700">(</font><font color="#DD0000">'document.pdf'</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font><br />
136 </font><br />
137 </code></blockquote><br />
138 <br />
139 </pre></p>
140 <h2 id="http_redirect">void http_redirect([string url[, array params[, bool session,[ bool permanent]]]])</h2>
141 <p>Redirect to a given url.<br />
142 The supplied url will be expanded with http_absolute_uri(), the params array will<br />
143 be treated with http_build_query() and the session identification will be appended<br />
144 if session is true.<br />
145 <br />
146 Depending on permanent the redirection will be issued with a permanent<br />
147 ("301 Moved Permanently") or a temporary ("302 Found") redirection<br />
148 status code.<br />
149 <br />
150 To be RFC compliant, "Redirecting to <a>URI</a>." will be displayed,<br />
151 if the client doesn't redirect immediatly.</p>
152 <h2 id="http_send_data">bool http_send_data(string data)</h2>
153 <p>Sends raw data with support for (multiple) range requests.</p>
154 <h2 id="http_send_file">bool http_send_file(string file)</h2>
155 <p>Sends a file with support for (multiple) range requests.</p>
156 <h2 id="http_send_stream">bool http_send_stream(resource stream)</h2>
157 <p>Sends an already opened stream with support for (multiple) range requests.</p>
158 <h2 id="http_chunked_decode">string http_chunked_decode(string encoded)</h2>
159 <p>This function decodes a string that was HTTP-chunked encoded.<br />
160 Returns false on failure.</p>
161 <h2 id="http_split_response">array http_split_response(string http_response)</h2>
162 <p>This function splits an HTTP response into an array with headers and the<br />
163 content body. The returned array may look simliar to the following example:</p><pre><blockquote><code><font color="#000000"><br />
164 <font color="#0000BB">&lt;?php<br /></font><font color="#007700">array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">0 </font><font color="#007700">=&gt; array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'Response Status' </font><font color="#007700">=&gt; </font><font color="#DD0000">'200 Ok'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'Content-Type' </font><font color="#007700">=&gt; </font><font color="#DD0000">'text/plain'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'Content-Language' </font><font color="#007700">=&gt; </font><font color="#DD0000">'en-US'<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">1 </font><font color="#007700">=&gt; </font><font color="#DD0000">"Hello World!"<br /></font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font><br />
165 </font><br />
166 </code></blockquote><br />
167 <br />
168 </pre></p>
169 <h2 id="http_parse_headers">array http_parse_headers(string header)</h2>
170 <p></p>
171 <h2 id="http_get_request_headers">array http_get_request_headers(void)</h2>
172 <p></p>
173 <h2 id="http_get">string http_get(string url[, array options[, array &info]])</h2>
174 <p>Performs an HTTP GET request on the supplied url.<br />
175 <br />
176 The second parameter is expected to be an associative<br />
177 array where the following keys will be recognized:</p><pre> - redirect: int, whether and how many redirects to follow<br />
178 - unrestrictedauth: bool, whether to continue sending credentials on<br />
179 redirects to a different host<br />
180 - proxyhost: string, proxy host in "host[:port]" format<br />
181 - proxyport: int, use another proxy port as specified in proxyhost<br />
182 - proxyauth: string, proxy credentials in "user:pass" format<br />
183 - proxyauthtype: int, HTTP_AUTH_BASIC and/or HTTP_AUTH_NTLM<br />
184 - httpauth: string, http credentials in "user:pass" format<br />
185 - httpauthtype: int, HTTP_AUTH_BASIC, DIGEST and/or NTLM<br />
186 - compress: bool, whether to allow gzip/deflate content encoding<br />
187 (defaults to true)<br />
188 - port: int, use another port as specified in the url<br />
189 - referer: string, the referer to sends<br />
190 - useragent: string, the user agent to send<br />
191 (defaults to PECL::HTTP/version (PHP/version)))<br />
192 - headers: array, list of custom headers as associative array<br />
193 like array("header" => "value")<br />
194 - cookies: array, list of cookies as associative array<br />
195 like array("cookie" => "value")<br />
196 - cookiestore: string, path to a file where cookies are/will be stored<br />
197 - resume: int, byte offset to start the download from;<br />
198 if the server supports ranges<br />
199 - maxfilesize: int, maximum file size that should be downloaded;<br />
200 has no effect, if the size of the requested entity is not known<br />
201 - lastmodified: int, timestamp for If-(Un)Modified-Since header<br />
202 - timeout: int, seconds the request may take<br />
203 - connecttimeout: int, seconds the connect may take<br />
204 - onprogress: mixed, progress callback<br />
205 - ondebug: mixed, debug callback</pre><p>The optional third parameter will be filled with some additional information<br />
206 in form af an associative array, if supplied, like the following example:</p><pre><blockquote><code><font color="#000000"><br />
207 <font color="#0000BB">&lt;?php<br /></font><font color="#007700">array (<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'effective_url' </font><font color="#007700">=&gt; </font><font color="#DD0000">'http://localhost'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'response_code' </font><font color="#007700">=&gt; </font><font color="#0000BB">403</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'total_time' </font><font color="#007700">=&gt; </font><font color="#0000BB">0.017</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'namelookup_time' </font><font color="#007700">=&gt; </font><font color="#0000BB">0.013</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'connect_time' </font><font color="#007700">=&gt; </font><font color="#0000BB">0.014</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'pretransfer_time' </font><font color="#007700">=&gt; </font><font color="#0000BB">0.014</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'size_upload' </font><font color="#007700">=&gt; </font><font color="#0000BB">0</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'size_download' </font><font color="#007700">=&gt; </font><font color="#0000BB">202</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'speed_download' </font><font color="#007700">=&gt; </font><font color="#0000BB">11882</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'speed_upload' </font><font color="#007700">=&gt; </font><font color="#0000BB">0</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'header_size' </font><font color="#007700">=&gt; </font><font color="#0000BB">145</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'request_size' </font><font color="#007700">=&gt; </font><font color="#0000BB">62</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'ssl_verifyresult' </font><font color="#007700">=&gt; </font><font color="#0000BB">0</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'filetime' </font><font color="#007700">=&gt; -</font><font color="#0000BB">1</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'content_length_download' </font><font color="#007700">=&gt; </font><font color="#0000BB">202</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'content_length_upload' </font><font color="#007700">=&gt; </font><font color="#0000BB">0</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'starttransfer_time' </font><font color="#007700">=&gt; </font><font color="#0000BB">0.017</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'content_type' </font><font color="#007700">=&gt; </font><font color="#DD0000">'text/html; charset=iso-8859-1'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'redirect_time' </font><font color="#007700">=&gt; </font><font color="#0000BB">0</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'redirect_count' </font><font color="#007700">=&gt; </font><font color="#0000BB">0</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'private' </font><font color="#007700">=&gt; </font><font color="#DD0000">''</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'http_connectcode' </font><font color="#007700">=&gt; </font><font color="#0000BB">0</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'httpauth_avail' </font><font color="#007700">=&gt; </font><font color="#0000BB">0</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'proxyauth_avail' </font><font color="#007700">=&gt; </font><font color="#0000BB">0</font><font color="#007700">,<br />)<br /></font><font color="#0000BB">?&gt;</font><br />
208 </font><br />
209 </code></blockquote><br />
210 <br />
211 </pre></p>
212 <h2 id="http_head">string http_head(string url[, array options[, array &info]])</h2>
213 <p>Performs an HTTP HEAD request on the suppied url.<br />
214 Returns the HTTP response as string.<br />
215 See http_get() for a full list of available options.</p>
216 <h2 id="http_post_data">string http_post_data(string url, string data[, array options[, &info]])</h2>
217 <p>Performs an HTTP POST request, posting data.<br />
218 Returns the HTTP response as string.<br />
219 See http_get() for a full list of available options.</p>
220 <h2 id="http_post_fields">string http_post_fields(string url, array data[, array files[, array options[, array &info]]])</h2>
221 <p>Performs an HTTP POST request, posting www-form-urlencoded array data.<br />
222 Returns the HTTP response as string.<br />
223 See http_get() for a full list of available options.</p>
224 <h2 id="http_put_file">string http_put_file(string url, string file[, array options[, array &info]])</h2>
225 <p></p>
226 <h2 id="http_put_stream">string http_put_stream(string url, resource stream[, array options[, array &info]])</h2>
227 <p></p>
228 <h2 id="http_request_method_register">bool http_request()</h2>
229 <p>}}} */<br />
230 <br />
231 /* {{{ proto long http_request_method_register(string method)</p>
232 <h2 id="http_request_method_unregister">bool http_request_method_unregister(mixed method)</h2>
233 <p></p>
234 <h2 id="http_request_method_exists">long http_request_method_exists(mixed method)</h2>
235 <p></p>
236 <h2 id="http_request_method_name">string http_request_method_name(long method)</h2>
237 <p></p>
238 <h2 id="http_auth_basic">bool http_auth_basic(string user, string pass[, string realm = "Restricted"])</h2>
239 <p>Example:</p><pre><blockquote><code><font color="#000000"><br />
240 <font color="#0000BB">&lt;?php<br /></font><font color="#007700">if (!</font><font color="#0000BB">http_auth_basic</font><font color="#007700">(</font><font color="#DD0000">'mike'</font><font color="#007700">, </font><font color="#DD0000">'s3c|r3t'</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</font><font color="#DD0000">'&lt;h1&gt;Authorization failed!&lt;/h1&gt;'</font><font color="#007700">);<br />}<br /></font><font color="#0000BB">?&gt;</font><br />
241 </font><br />
242 </code></blockquote><br />
243 <br />
244 </pre></p>
245 <h2 id="http_auth_basic_cb">bool http_auth_basic_cb(mixed callback[, string realm = "Restricted"])</h2>
246 <p>Example:</p><pre><blockquote><code><font color="#000000"><br />
247 <font color="#0000BB">&lt;?php<br /></font><font color="#007700">function </font><font color="#0000BB">auth_cb</font><font color="#007700">(</font><font color="#0000BB">$user</font><font color="#007700">, </font><font color="#0000BB">$pass</font><font color="#007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;global </font><font color="#0000BB">$db</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$query </font><font color="#007700">= </font><font color="#DD0000">'SELECT pass FROM users WHERE user='</font><font color="#007700">. </font><font color="#0000BB">$db</font><font color="#007700">-&gt;</font><font color="#0000BB">quoteSmart</font><font color="#007700">(</font><font color="#0000BB">$user</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;if (</font><font color="#0000BB">strlen</font><font color="#007700">(</font><font color="#0000BB">$realpass </font><font color="#007700">= </font><font color="#0000BB">$db</font><font color="#007700">-&gt;</font><font color="#0000BB">getOne</font><font color="#007700">(</font><font color="#0000BB">$query</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return </font><font color="#0000BB">$pass </font><font color="#007700">=== </font><font color="#0000BB">$realpass</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;return </font><font color="#0000BB">false</font><font color="#007700">;<br />}<br />if (!</font><font color="#0000BB">http_auth_basic_cb</font><font color="#007700">(</font><font color="#DD0000">'auth_cb'</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</font><font color="#DD0000">'&lt;h1&gt;Authorization failed&lt;/h1&gt;'</font><font color="#007700">);<br />}<br /></font><font color="#0000BB">?&gt;</font><br />
248 </font><br />
249 </code></blockquote><br />
250 <br />
251 </pre></p>
252 <h2 id="http_build_query">string http_build_query(mixed formdata [, string prefix[, string arg_separator]])</h2>
253 <p>Generates a form-encoded query string from an associative array or object.</p>
254 <hr noshade>
255 <h1>http_methods.c</h1>
256 <h2 id="HttpResponse" class="o">HttpResponse</h2>
257 <h3 id="HttpResponse___construct">void HttpResponse::__construct(bool cache, bool gzip)</h3>
258 <p>Instantiates a new HttpResponse object, which can be used to send<br />
259 any data/resource/file to an HTTP client with caching and multiple<br />
260 ranges/resuming support.<br />
261 <br />
262 NOTE: GZIPping is not implemented yet.</p>
263 <h3 id="HttpResponse_setCache">bool HttpResponse::setCache(bool cache)</h3>
264 <p>Whether it sould be attempted to cache the entitity.<br />
265 This will result in necessary caching headers and checks of clients<br />
266 "If-Modified-Since" and "If-None-Match" headers. If one of those headers<br />
267 matches a "304 Not Modified" status code will be issued.<br />
268 <br />
269 NOTE: If you're using sessions, be shure that you set session.cache_limiter<br />
270 to something more appropriate than "no-cache"!</p>
271 <h3 id="HttpResponse_getCache">bool HttpResponse::getCache()</h3>
272 <p>Get current caching setting.</p>
273 <h3 id="HttpResponse_setGzip">bool HttpResponse::setGzip(bool gzip)</h3>
274 <p>Enable on-thy-fly gzipping of the sent entity. NOT IMPLEMENTED YET.</p>
275 <h3 id="HttpResponse_getGzip">bool HttpResponse::getGzip()</h3>
276 <p>Get current gzipping setting.</p>
277 <h3 id="HttpResponse_setCacheControl">bool HttpResponse::setCacheControl(string control[, bool raw = false])</h3>
278 <p>Set a custom cache-control header, usually being "private" or "public"; if<br />
279 $raw is set to true the header will be sent as-is.</p>
280 <h3 id="HttpResponse_getCacheControl">string HttpResponse::getCacheControl()</h3>
281 <p>Get current Cache-Control header setting.</p>
282 <h3 id="HttpResponse_setContentType">bool HttpResponse::setContentType(string content_type)</h3>
283 <p>Set the content-type of the sent entity.</p>
284 <h3 id="HttpResponse_getContentType">string HttpResponse::getContentType()</h3>
285 <p>Get current Content-Type header setting.</p>
286 <h3 id="HttpResponse_setContentDisposition">bool HttpResponse::setContentDisposition(string filename[, bool inline = false])</h3>
287 <p>Set the Content-Disposition of the sent entity. This setting aims to suggest<br />
288 the receiveing user agent how to handle the sent entity; usually the client<br />
289 will show the user a "Save As..." popup.</p>
290 <h3 id="HttpResponse_getContentDisposition">array HttpResponse::getContentDisposition()</h3>
291 <p>Get current Content-Disposition setting.<br />
292 Will return an associative array like:</p><pre>array(<br />
293 'filename' => 'foo.bar',<br />
294 'inline' => false<br />
295 )<br />
296 </pre></p>
297 <h3 id="HttpResponse_setETag">bool HttpResponse::setETag(string etag)</h3>
298 <p>Set a custom ETag. Use this only if you know what you're doing.</p>
299 <h3 id="HttpResponse_getETag">string HttpResponse::getETag()</h3>
300 <p>Get the previously set custom ETag.</p>
301 <h3 id="HttpResponse_setThrottleDelay">void HttpResponse::setThrottleDelay(double seconds)</h3>
302 <p></p>
303 <h3 id="HttpResponse_getThrottleDelay">double HttpResponse::getThrottleDelay()</h3>
304 <p></p>
305 <h3 id="HttpResponse_setSendBuffersize">void HttpResponse::setSendBuffersize(long bytes)</h3>
306 <p></p>
307 <h3 id="HttpResponse_getSendBuffersize">long HttpResponse::getSendBuffersize()</h3>
308 <p></p>
309 <h3 id="HttpResponse_setData">bool HttpResponse::setData(string data)</h3>
310 <p>Set the data to be sent.</p>
311 <h3 id="HttpResponse_getData">string HttpResponse::getData()</h3>
312 <p>Get the previously set data to be sent.</p>
313 <h3 id="HttpResponse_setStream">bool HttpResponse::setStream(resource stream)</h3>
314 <p>Set the resource to be sent.</p>
315 <h3 id="HttpResponse_getStream">resource HttpResponse::getStream()</h3>
316 <p>Get the previously set resource to be sent.</p>
317 <h3 id="HttpResponse_setFile">bool HttpResponse::setFile(string file)</h3>
318 <p>Set the file to be sent.</p>
319 <h3 id="HttpResponse_getFile">string HttpResponse::getFile()</h3>
320 <p>Get the previously set file to be sent.</p>
321 <h3 id="HttpResponse_send">bool HttpResponse::send()</h3>
322 <p>Finally send the entity.<br />
323 <br />
324 Example:</p><pre><blockquote><code><font color="#000000"><br />
325 <font color="#0000BB">&lt;?php<br />$r </font><font color="#007700">= new </font><font color="#0000BB">HttpResponse</font><font color="#007700">(</font><font color="#0000BB">true</font><font color="#007700">);<br /></font><font color="#0000BB">$r</font><font color="#007700">-&gt;</font><font color="#0000BB">setFile</font><font color="#007700">(</font><font color="#DD0000">'../hidden/contract.pdf'</font><font color="#007700">);<br /></font><font color="#0000BB">$r</font><font color="#007700">-&gt;</font><font color="#0000BB">setContentType</font><font color="#007700">(</font><font color="#DD0000">'application/pdf'</font><font color="#007700">);<br /></font><font color="#0000BB">$r</font><font color="#007700">-&gt;</font><font color="#0000BB">send</font><font color="#007700">();<br /></font><font color="#0000BB">?&gt;</font><br />
326 </font><br />
327 </code></blockquote><br />
328 <br />
329 </pre></p>
330 <h3 id="HttpMessage_fromString">static HttpMessage HttpMessage::fromString(string raw_message)</h3>
331 <p>Create an HttpMessage object from a string.</p>
332 <h2 id="HttpMessage" class="o">HttpMessage</h2>
333 <h3 id="HttpMessage___construct">void HttpMessage::__construct([string message])</h3>
334 <p>Instantiate a new HttpMessage object.</p>
335 <h3 id="HttpMessage_getBody">string HttpMessage::getBody()</h3>
336 <p>Get the body of the parsed Message.</p>
337 <h3 id="HttpMessage_getHeaders">array HttpMessage::getHeaders()</h3>
338 <p>Get Message Headers.</p>
339 <h3 id="HttpMessage_setHeaders">void HttpMessage::setHeaders(array headers)</h3>
340 <p>Sets new headers.</p>
341 <h3 id="HttpMessage_addHeaders">void HttpMessage::addHeaders(array headers[, bool append = false])</h3>
342 <p>Add headers. If append is true, headers with the same name will be separated, else overwritten.</p>
343 <h3 id="HttpMessage_getType">long HttpMessage::getType()</h3>
344 <p>Get Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE)</p>
345 <h3 id="HttpMessage_setType">void HttpMessage::setType(long type)</h3>
346 <p>Set Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE)</p>
347 <h3 id="HttpMessage_getResponseCode">long HttpMessage::getResponseCode()</h3>
348 <p>Get the Response Code of the Message.</p>
349 <h3 id="HttpMessage_setResponseCode">bool HttpMessage::setResponseCode(long code)</h3>
350 <p>Set the response code of an HTTP Response Message.<br />
351 Returns false if the Message is not of type HTTP_MSG_RESPONSE,<br />
352 or if the response code is out of range (100-510).</p>
353 <h3 id="HttpMessage_getRequestMethod">string HttpMessage::getRequestMethod()</h3>
354 <p>Get the Request Method of the Message.<br />
355 Returns false if the Message is not of type HTTP_MSG_REQUEST.</p>
356 <h3 id="HttpMessage_setRequestMethod">bool HttpMessage::setRequestMethod(string method)</h3>
357 <p>Set the Request Method of the HTTP Message.<br />
358 Returns false if the Message is not of type HTTP_MSG_REQUEST.</p>
359 <h3 id="HttpMessage_getRequestUri">string HttpMessage::getRequestUri()</h3>
360 <p>Get the Request URI of the Message.</p>
361 <h3 id="HttpMessage_setRequestUri">bool HttpMessage::setRequestUri(string URI)</h3>
362 <p>Set the Request URI of the HTTP Message.<br />
363 Returns false if the Message is not of type HTTP_MSG_REQUEST,<br />
364 or if paramtere URI was empty.</p>
365 <h3 id="HttpMessage_getHttpVersion">string HttpMessage::getHttpVersion()</h3>
366 <p>Get the HTTP Protocol Version of the Message.</p>
367 <h3 id="HttpMessage_setHttpVersion">bool HttpMessage::setHttpVersion(string version)</h3>
368 <p>Set the HTTP Protocol version of the Message.<br />
369 Returns false if version is invalid (1.0 and 1.1).</p>
370 <h3 id="HttpMessage_getParentMessage">HttpMessage HttpMessage::getParentMessage()</h3>
371 <p>Get parent Message.</p>
372 <h3 id="HttpMessage_send">bool HttpMessage::send()</h3>
373 <p>Send the Message according to its type as Response or Request.</p>
374 <h3 id="HttpMessage_toString">string HttpMessage::toString([bool include_parent = true])</h3>
375 <p>Get the string representation of the Message.</p>
376 <h2 id="HttpRequest" class="o">HttpRequest</h2>
377 <h3 id="HttpRequest___construct">void HttpRequest::__construct([string url[, long request_method = HTTP_GET]])</h3>
378 <p>Instantiate a new HttpRequest object which can be used to issue HEAD, GET<br />
379 and POST (including posting files) HTTP requests.</p>
380 <h3 id="HttpRequest___destruct">void HttpRequest::__destruct()</h3>
381 <p>Destroys the HttpRequest object.</p>
382 <h3 id="HttpRequest_setOptions">bool HttpRequest::setOptions(array options)</h3>
383 <p>Set the request options to use. See http_get() for a full list of available options.</p>
384 <h3 id="HttpRequest_getOptions">array HttpRequest::getOptions()</h3>
385 <p>Get current set options.</p>
386 <h3 id="HttpRequest_unsetOptions">void HttpRequest::unsetOptions()</h3>
387 <p>Unset all options/headers/cookies.</p>
388 <h3 id="HttpRequest_setSslOptions">bool HttpRequest::setSslOptions(array options)</h3>
389 <p>Set additional SSL options.</p>
390 <h3 id="HttpRequest_getSslOptions">array HttpRequest::getSslOtpions()</h3>
391 <p>Get previously set SSL options.</p>
392 <h3 id="HttpRequest_unsetSslOptions">void HttpRequest::unsetSslOptions()</h3>
393 <p>Unset previously set SSL options.</p>
394 <h3 id="HttpRequest_addHeaders">bool HttpRequest::addHeaders(array headers)</h3>
395 <p>Add request header name/value pairs.</p>
396 <h3 id="HttpRequest_getHeaders">array HttpRequest::getHeaders()</h3>
397 <p>Get previously set request headers.</p>
398 <h3 id="HttpRequest_unsetHeaders">void HttpRequest::unsetHeaders()</h3>
399 <p>Unset previously set request headers.</p>
400 <h3 id="HttpRequest_addCookies">bool HttpRequest::addCookies(array cookies)</h3>
401 <p>Add cookies.</p>
402 <h3 id="HttpRequest_getCookies">array HttpRequest::getCookies()</h3>
403 <p>Get previously set cookies.</p>
404 <h3 id="HttpRequest_unsetCookies">void HttpRequest::unsetCookies()</h3>
405 <p></p>
406 <h3 id="HttpRequest_setURL">bool HttpRequest::setURL(string url)</h3>
407 <p>Set the request URL.</p>
408 <h3 id="HttpRequest_getURL">string HttpRequest::getUrl()</h3>
409 <p>Get the previously set request URL.</p>
410 <h3 id="HttpRequest_setMethod">bool HttpRequest::setMethod(long request_method)</h3>
411 <p>Set the request methods; one of the <tt>HTTP_HEAD</tt>, <tt>HTTP_GET</tt> or<br />
412 <tt>HTTP_POST</tt> constants.</p>
413 <h3 id="HttpRequest_getMethod">long HttpRequest::getMethod()</h3>
414 <p>Get the previously set request method.</p>
415 <h3 id="HttpRequest_setContentType">bool HttpRequest::setContentType(string content_type)</h3>
416 <p>Set the content type the post request should have.<br />
417 Use this only if you know what you're doing.</p>
418 <h3 id="HttpRequest_getContentType">string HttpRequest::getContentType()</h3>
419 <p>Get the previously content type.</p>
420 <h3 id="HttpRequest_setQueryData">bool HttpRequest::setQueryData(mixed query_data)</h3>
421 <p>Set the URL query parameters to use.<br />
422 Overwrites previously set query parameters.<br />
423 Affects any request types.</p>
424 <h3 id="HttpRequest_getQueryData">string HttpRequest::getQueryData()</h3>
425 <p>Get the current query data in form of an urlencoded query string.</p>
426 <h3 id="HttpRequest_addQueryData">bool HttpRequest::addQueryData(array query_params)</h3>
427 <p>Add parameters to the query parameter list.<br />
428 Affects any request type.</p>
429 <h3 id="HttpRequest_unsetQueryData">void HttpRequest::unsetQueryData()</h3>
430 <p>Clean the query parameters.<br />
431 Affects any request type.</p>
432 <h3 id="HttpRequest_addPostFields">bool HttpRequest::addPostFields(array post_data)</h3>
433 <p>Adds POST data entries.<br />
434 Affects only POST requests.</p>
435 <h3 id="HttpRequest_setPostFields">bool HttpRequest::setPostFields(array post_data)</h3>
436 <p>Set the POST data entries.<br />
437 Overwrites previously set POST data.<br />
438 Affects only POST requests.</p>
439 <h3 id="HttpRequest_getPostFields">array HttpRequest::getPostFields()</h3>
440 <p>Get previously set POST data.</p>
441 <h3 id="HttpRequest_unsetPostFields">void HttpRequest::unsetPostFields()</h3>
442 <p>Clean POST data entires.<br />
443 Affects only POST requests.</p>
444 <h3 id="HttpRequest_addPostFile">bool HttpRequest::addPostFile(string name, string file[, string content_type = "application/x-octetstream"])</h3>
445 <p>Add a file to the POST request.<br />
446 Affects only POST requests.</p>
447 <h3 id="HttpRequest_getPostFiles">array HttpRequest::getPostFiles()</h3>
448 <p>Get all previously added POST files.</p>
449 <h3 id="HttpRequest_unsetPostFiles">void HttpRequest::unsetPostFiles()</h3>
450 <p>Unset the POST files list.<br />
451 Affects only POST requests.</p>
452 <h3 id="HttpRequest_getResponseData">array HttpRequest::getResponseData()</h3>
453 <p>Get all response data after the request has been sent.</p>
454 <h3 id="HttpRequest_getResponseHeader">mixed HttpRequest::getResponseHeader([string name])</h3>
455 <p>Get response header(s) after the request has been sent.</p>
456 <h3 id="HttpRequest_getResponseCookie">array HttpRequest::getResponseCookie([string name])</h3>
457 <p>Get response cookie(s) after the request has been sent.</p>
458 <h3 id="HttpRequest_getResponseBody">string HttpRequest::getResponseBody()</h3>
459 <p>Get the response body after the request has been sent.</p>
460 <h3 id="HttpRequest_getResponseCode">int HttpRequest::getResponseCode()</h3>
461 <p>Get the response code after the request has been sent.</p>
462 <h3 id="HttpRequest_getResponseInfo">array HttpRequest::getResponseInfo([string name])</h3>
463 <p>Get response info after the request has been sent.<br />
464 See http_get() for a full list of returned info.</p>
465 <h3 id="HttpRequest_getResponseMessage">HttpMessage HttpRequest::getResponseMessage()</h3>
466 <p>Get the full response as HttpMessage object.</p>
467 <h3 id="HttpRequest_send">bool HttpRequest::send()</h3>
468 <p>Send the HTTP request.<br />
469 <br />
470 GET example:</p><pre><blockquote><code><font color="#000000"><br />
471 <font color="#0000BB">&lt;?php<br />$r </font><font color="#007700">= new </font><font color="#0000BB">HttpRequest</font><font color="#007700">(</font><font color="#DD0000">'http://example.com/feed.rss'</font><font color="#007700">, </font><font color="#0000BB">HTTP_GET</font><font color="#007700">);<br /></font><font color="#0000BB">$r</font><font color="#007700">-&gt;</font><font color="#0000BB">setOptions</font><font color="#007700">(array(</font><font color="#DD0000">'lastmodified' </font><font color="#007700">=&gt; </font><font color="#0000BB">filemtime</font><font color="#007700">(</font><font color="#DD0000">'local.rss'</font><font color="#007700">)));<br /></font><font color="#0000BB">$r</font><font color="#007700">-&gt;</font><font color="#0000BB">addQueryData</font><font color="#007700">(array(</font><font color="#DD0000">'category' </font><font color="#007700">=&gt; </font><font color="#0000BB">3</font><font color="#007700">));<br /></font><font color="#0000BB">try </font><font color="#007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$r</font><font color="#007700">-&gt;</font><font color="#0000BB">send</font><font color="#007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;if (</font><font color="#0000BB">$r</font><font color="#007700">-&gt;</font><font color="#0000BB">getResponseCode</font><font color="#007700">() == </font><font color="#0000BB">200</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">file_put_contents</font><font color="#007700">(</font><font color="#DD0000">'local.rss'</font><font color="#007700">, </font><font color="#0000BB">$r</font><font color="#007700">-&gt;</font><font color="#0000BB">getResponseBody</font><font color="#007700">());<br />&nbsp;&nbsp;&nbsp;}<br />} </font><font color="#0000BB">catch </font><font color="#007700">(</font><font color="#0000BB">HttpException $ex</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#0000BB">$ex</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?&gt;</font><br />
472 </font><br />
473 </code></blockquote></pre><p>POST example:</p><pre><blockquote><code><font color="#000000"><br />
474 <font color="#0000BB">&lt;?php<br />$r </font><font color="#007700">= new </font><font color="#0000BB">HttpRequest</font><font color="#007700">(</font><font color="#DD0000">'http://example.com/form.php'</font><font color="#007700">, </font><font color="#0000BB">HTTP_POST</font><font color="#007700">);<br /></font><font color="#0000BB">$r</font><font color="#007700">-&gt;</font><font color="#0000BB">setOptions</font><font color="#007700">(array(</font><font color="#DD0000">'cookies' </font><font color="#007700">=&gt; array(</font><font color="#DD0000">'lang' </font><font color="#007700">=&gt; </font><font color="#DD0000">'de'</font><font color="#007700">)));<br /></font><font color="#0000BB">$r</font><font color="#007700">-&gt;</font><font color="#0000BB">addpostFields</font><font color="#007700">(array(</font><font color="#DD0000">'user' </font><font color="#007700">=&gt; </font><font color="#DD0000">'mike'</font><font color="#007700">, </font><font color="#DD0000">'pass' </font><font color="#007700">=&gt; </font><font color="#DD0000">'s3c|r3t'</font><font color="#007700">));<br /></font><font color="#0000BB">$r</font><font color="#007700">-&gt;</font><font color="#0000BB">addPostFile</font><font color="#007700">(</font><font color="#DD0000">'image'</font><font color="#007700">, </font><font color="#DD0000">'profile.jpg'</font><font color="#007700">, </font><font color="#DD0000">'image/jpeg'</font><font color="#007700">);<br />if (</font><font color="#0000BB">$r</font><font color="#007700">-&gt;</font><font color="#0000BB">send</font><font color="#007700">()) {<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#0000BB">$r</font><font color="#007700">-&gt;</font><font color="#0000BB">getResponseBody</font><font color="#007700">();<br />}<br /></font><font color="#0000BB">?&gt;</font><br />
475 </font><br />
476 </code></blockquote><br />
477 <br />
478 </pre></p>
479 <hr noshade>
480 <p><b>Generated at: Wed, 25 May 2005 19:01:02 +0200</b></p>
481 </body>
482 </html>
483