This function returns a valid HTTP date regarding RFC 822/1123
looking like: "Wed, 22 Dec 2004 11:34:47 GMT"
This function returns an absolute URI constructed from url.
If the url is already abolute but a different proto was supplied,
only the proto part of the URI will be updated. If url has no
path specified, the path of the current REQUEST_URI will be taken.
The host will be taken either from the Host HTTP header of the client
the SERVER_NAME or just localhost if prior are not available.
Some examples:
url = "page.php" => http://www.example.com/current/path/page.php
url = "/page.php" => http://www.example.com/page.php
url = "/page.php", proto = "https" => https://www.example.com/page.php
This function negotiates the clients preferred language based on its
Accept-Language HTTP header. It returns the negotiated language or
the default language if none match.
The qualifier is recognized and languages without qualifier are rated highest.
The supported parameter is expected to be an array having
the supported languages as array values.
Example:
<?php
$langs = array(
'en-US',// default
'fr',
'fr-FR',
'de',
'de-DE',
'de-AT',
'de-CH',
);
include './langs/'. http_negotiate_language($langs) .'.php';
?>
This function negotiates the clients preferred charset based on its
Accept-Charset HTTP header. It returns the negotiated charset or
the default charset if none match.
The qualifier is recognized and charset without qualifier are rated highest.
The supported parameter is expected to be an array having
the supported charsets as array values.
Example:
<?php
$charsets = array(
'iso-8859-1', // default
'iso-8859-2',
'iso-8859-15',
'utf-8'
);
$pref = http_negotiate_charset($charsets);
if (!strcmp($pref, 'iso-8859-1')) {
iconv_set_encoding('internal_encoding', 'iso-8859-1');
iconv_set_encoding('output_encoding', $pref);
ob_start('ob_iconv_handler');
}
?>
Send HTTP status code.
This converts the given timestamp to a valid HTTP date and
sends it as "Last-Modified" HTTP header. If timestamp is
omitted, current time is sent.
Sets the content type.
Set the Content Disposition. The Content-Disposition header is very useful
if the data actually sent came from a file or something similar, that should
be "saved" by the client/user (i.e. by browsers "Save as..." popup window).
Matches the given timestamp against the clients "If-Modified-Since" resp.
"If-Unmodified-Since" HTTP headers.
This matches the given ETag against the clients
"If-Match" resp. "If-None-Match" HTTP headers.
If timestamp_or_expires is greater than 0, it is handled as timestamp
and will be sent as date of last modification. If it is 0 or omitted,
the current time will be sent as Last-Modified date. If it's negative,
it is handled as expiration time in seconds, which means that if the
requested last modification date is not between the calculated timespan,
the Last-Modified header is updated and the actual body will be sent.
This function attempts to cache the HTTP body based on an ETag,
either supplied or generated through calculation of the MD5
checksum of the output (uses output buffering).
If clients "If-None-Match" header matches the supplied/calculated
ETag, the body is considered cached on the clients side and
a "304 Not Modified" status code is issued.
For use with ob_start().
Use with http_send() API.
Example:
<?php
// ~ 20 kbyte/s
# http_throttle(1, 20000);
# http_throttle(0.5, 10000);
# http_throttle(0.1, 2000);
http_send_file('document.pdf');
?>
Redirect to a given url.
The supplied url will be expanded with http_absolute_uri(), the params array will
be treated with http_build_query() and the session identification will be appended
if session is true.
Depending on permanent the redirection will be issued with a permanent
("301 Moved Permanently") or a temporary ("302 Found") redirection
status code.
To be RFC compliant, "Redirecting to URI." will be displayed,
if the client doesn't redirect immediatly.
Sends raw data with support for (multiple) range requests.
Sends a file with support for (multiple) range requests.
Sends an already opened stream with support for (multiple) range requests.
This function decodes a string that was HTTP-chunked encoded.
Returns false on failure.
This function splits an HTTP response into an array with headers and the
content body. The returned array may look simliar to the following example:
<?php
array(
0 => array(
'Response Status' => '200 Ok',
'Content-Type' => 'text/plain',
'Content-Language' => 'en-US'
),
1 => "Hello World!"
);
?>
Get a list of incoming HTTP headers.
Get the raw request body (e.g. POST or PUT data).
Match an incoming HTTP header.
Performs an HTTP GET request on the supplied url.
The second parameter is expected to be an associative
array where the following keys will be recognized:
- redirect: int, whether and how many redirects to follow
- unrestrictedauth: bool, whether to continue sending credentials on
redirects to a different host
- proxyhost: string, proxy host in "host[:port]" format
- proxyport: int, use another proxy port as specified in proxyhost
- proxyauth: string, proxy credentials in "user:pass" format
- proxyauthtype: int, HTTP_AUTH_BASIC and/or HTTP_AUTH_NTLM
- httpauth: string, http credentials in "user:pass" format
- httpauthtype: int, HTTP_AUTH_BASIC, DIGEST and/or NTLM
- compress: bool, whether to allow gzip/deflate content encoding
(defaults to true)
- port: int, use another port as specified in the url
- referer: string, the referer to sends
- useragent: string, the user agent to send
(defaults to PECL::HTTP/version (PHP/version)))
- headers: array, list of custom headers as associative array
like array("header" => "value")
- cookies: array, list of cookies as associative array
like array("cookie" => "value")
- cookiestore: string, path to a file where cookies are/will be stored
- resume: int, byte offset to start the download from;
if the server supports ranges
- maxfilesize: int, maximum file size that should be downloaded;
has no effect, if the size of the requested entity is not known
- lastmodified: int, timestamp for If-(Un)Modified-Since header
- timeout: int, seconds the request may take
- connecttimeout: int, seconds the connect may take
- onprogress: mixed, progress callback
The optional third parameter will be filled with some additional information
in form af an associative array, if supplied, like the following example:
<?php
array (
'effective_url' => 'http://localhost',
'response_code' => 403,
'total_time' => 0.017,
'namelookup_time' => 0.013,
'connect_time' => 0.014,
'pretransfer_time' => 0.014,
'size_upload' => 0,
'size_download' => 202,
'speed_download' => 11882,
'speed_upload' => 0,
'header_size' => 145,
'request_size' => 62,
'ssl_verifyresult' => 0,
'filetime' => -1,
'content_length_download' => 202,
'content_length_upload' => 0,
'starttransfer_time' => 0.017,
'content_type' => 'text/html; charset=iso-8859-1',
'redirect_time' => 0,
'redirect_count' => 0,
'private' => '',
'http_connectcode' => 0,
'httpauth_avail' => 0,
'proxyauth_avail' => 0,
)
?>
Performs an HTTP HEAD request on the suppied url.
Returns the HTTP response as string.
See http_get() for a full list of available options.
Performs an HTTP POST request, posting data.
Returns the HTTP response as string.
See http_get() for a full list of available options.
Performs an HTTP POST request, posting www-form-urlencoded array data.
Returns the HTTP response as string.
See http_get() for a full list of available options.
Performs an HTTP PUT request, uploading file.
Returns the HTTP response as string.
See http_get() for a full list of available options.
Performs an HTTP PUT request, uploading stream.
Returns the HTTP response as string.
See http_get() for a full list of available options.
Register a custom request method.
Unregister a previously registered custom request method.
Check if a request method is registered (or available by default).
Get the literal string representation of a standard or registered request method.
Example:
<?php
if (!http_auth_basic('mike', 's3c|r3t')) {
die('<h1>Authorization failed!</h1>');
}
?>
Example:
<?php
function auth_cb($user, $pass)
{
global $db;
$query = 'SELECT pass FROM users WHERE user='. $db->quoteSmart($user);
if (strlen($realpass = $db->getOne($query)) {
return $pass === $realpass;
}
return false;
}
if (!http_auth_basic_cb('auth_cb')) {
die('<h1>Authorization failed</h1>');
}
?>
Generates a form-encoded query string from an associative array or object.
Instantiate a new HttpMessage object.
Create an HttpMessage object from a string.
Get the body of the parsed Message.
Get Message Headers.
Sets new headers.
Add headers. If append is true, headers with the same name will be separated, else overwritten.
Get Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE)
Set Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE)
Get the Response Code of the Message.
Set the response code of an HTTP Response Message.
Returns false if the Message is not of type HTTP_MSG_RESPONSE,
or if the response code is out of range (100-510).
Get the Request Method of the Message.
Returns false if the Message is not of type HTTP_MSG_REQUEST.
Set the Request Method of the HTTP Message.
Returns false if the Message is not of type HTTP_MSG_REQUEST.
Get the Request URI of the Message.
Set the Request URI of the HTTP Message.
Returns false if the Message is not of type HTTP_MSG_REQUEST,
or if paramtere URI was empty.
Get the HTTP Protocol Version of the Message.
Set the HTTP Protocol version of the Message.
Returns false if version is invalid (1.0 and 1.1).
Get parent Message.
Send the Message according to its type as Response or Request.
Get the string representation of the Message.
Instantiate a new HttpRequest object which can be used to issue HEAD, GET
and POST (including posting files) HTTP requests.
Destroys the HttpRequest object.
Set the request options to use. See http_get() for a full list of available options.
Get current set options.
Unset all options/headers/cookies.
Set additional SSL options.
Get previously set SSL options.
Unset previously set SSL options.
Add request header name/value pairs.
Get previously set request headers.
Unset previously set request headers.
Add cookies.
Get previously set cookies.
Set the request URL.
Get the previously set request URL.
Set the request methods; one of the HTTP_HEAD, HTTP_GET or
HTTP_POST constants.
Get the previously set request method.
Set the content type the post request should have.
Use this only if you know what you're doing.
Get the previously content type.
Set the URL query parameters to use.
Overwrites previously set query parameters.
Affects any request types.
Get the current query data in form of an urlencoded query string.
Add parameters to the query parameter list.
Affects any request type.
Clean the query parameters.
Affects any request type.
Adds POST data entries.
Affects only POST requests.
Set the POST data entries.
Overwrites previously set POST data.
Affects only POST requests.
Get previously set POST data.
Clean POST data entires.
Affects only POST requests.
Add a file to the POST request.
Affects only POST requests.
Set files to post.
Overwrites previously set post files.
Affects only POST requests.
Get all previously added POST files.
Unset the POST files list.
Affects only POST requests.
Set file to put.
Affects only PUT requests.
Get previously set put file.
Unset file to put.
Affects only PUT requests.
Get all response data after the request has been sent.
Get response header(s) after the request has been sent.
Get response cookie(s) after the request has been sent.
Get the response body after the request has been sent.
Get the response code after the request has been sent.
Get response info after the request has been sent.
See http_get() for a full list of returned info.
Get the full response as HttpMessage object.
Get sent HTTP message.
Send the HTTP request.
GET example:
<?php
$r = new HttpRequest('http://example.com/feed.rss', HTTP_GET);
$r->setOptions(array('lastmodified' => filemtime('local.rss')));
$r->addQueryData(array('category' => 3));
try {
$r->send();
if ($r->getResponseCode() == 200) {
file_put_contents('local.rss', $r->getResponseBody());
}
} catch (HttpException $ex) {
echo $ex;
}
?>
POST example:
<?php
$r = new HttpRequest('http://example.com/form.php', HTTP_POST);
$r->setOptions(array('cookies' => array('lang' => 'de')));
$r->addpostFields(array('user' => 'mike', 'pass' => 's3c|r3t'));
$r->addPostFile('image', 'profile.jpg', 'image/jpeg');
if ($r->send()) {
echo $r->getResponseBody();
}
?>
Instantiate a new HttpRequestPool object. An HttpRequestPool is
able to send several HttpRequests in parallel.
Example:
<?php
try {
$pool = new HttpRequestPool(
new HttpRequest('http://www.google.com/', HTTP_HEAD),
new HttpRequest('http://www.php.net/', HTTP_HEAD)
);
$pool->send();
foreach($pool as $request) {
printf("%s is %s (%d)\n",
$request->getUrl(),
$request->getResponseCode() ? 'alive' : 'not alive',
$request->getResponseCode()
);
}
} catch (HttpException $e) {
echo $e;
}
?>
Clean up HttpRequestPool object.
Detach all attached HttpRequest objects.
Attach an HttpRequest object to this HttpRequestPool.
NOTE: set all options prior attaching!
Detach an HttpRequest object from this HttpRequestPool.
Send all attached HttpRequest objects in parallel.
Usage:
<?php
while ($pool->socketSend()) {
do_something_else();
if (!$pool->socketSelect()) {
die('Socket error');
}
}
$pool->socketRead();
?>
See HttpRequestPool::socketSend().
See HttpRequestPool::socketSend().
Implements Iterator::valid().
Implements Iterator::current().
Implements Iterator::key().
Implements Iterator::next().
Implements Iterator::rewind().
Whether it sould be attempted to cache the entitity.
This will result in necessary caching headers and checks of clients
"If-Modified-Since" and "If-None-Match" headers. If one of those headers
matches a "304 Not Modified" status code will be issued.
NOTE: If you're using sessions, be shure that you set session.cache_limiter
to something more appropriate than "no-cache"!
Get current caching setting.
Enable on-thy-fly gzipping of the sent entity. NOT IMPLEMENTED YET.
Get current gzipping setting.
Set a custom cache-control header, usually being "private" or "public";
The max_age parameter controls how long the cache entry is valid on the client side.
Get current Cache-Control header setting.
Set the content-type of the sent entity.
Get current Content-Type header setting.
Set the Content-Disposition of the sent entity. This setting aims to suggest
the receiveing user agent how to handle the sent entity; usually the client
will show the user a "Save As..." popup.
Get current Content-Disposition setting.
Set a custom ETag. Use this only if you know what you're doing.
Get the previously set custom ETag.
Set the data to be sent.
Get the previously set data to be sent.
Set the resource to be sent.
Get the previously set resource to be sent.
Set the file to be sent.
Get the previously set file to be sent.
Finally send the entity.
Example:
<?php
HttpResponse::setCache(true);
HttpResponse::setContentType('application/pdf');
HttpResponse::setContentDisposition("$user.pdf", false);
HttpResponse::setFile('sheet.pdf');
HttpResponse::send();
?>
Capture script output.
Example:
<?php
HttpResponse::setCache(true);
HttpResponse::capture();
// script follows
?>
Generated at: Mon, 01 Aug 2005 09:46:36 +0200