HTTP2
[ class tree: HTTP2 ] [ index: HTTP2 ] [ all elements ]

Class: HTTP2

Source Location: /HTTP2-1.1.1/HTTP2.php

Class Overview


Miscellaneous HTTP Utilities


Author(s):

Version:

  • Release: 1.1.1

Methods


Inherited Variables

Inherited Methods


Class Details

[line 43]
Miscellaneous HTTP Utilities

PEAR::HTTP2 provides shorthand methods for generating HTTP dates, issueing HTTP HEAD requests, building absolute URIs, firing redirects and negotiating user preferred language.



[ Top ]


Method Detail

absoluteURI   [line 440]

string absoluteURI( [string $url = null], [string $protocol = null], [integer $port = null])

This function returns the absolute URI for the partial URL passed.

The current scheme (HTTP/HTTPS), host server, port, current script location are used if necessary to resolve any relative URLs.

Offsets potentially created by PATH_INFO are taken care of to resolve relative URLs to the current script.

You can choose a new protocol while resolving the URI. This is particularly useful when redirecting a web browser using relative URIs and to switch from HTTP to HTTPS, or vice-versa, at the same time.


Parameters:

string   $url     Absolute or relative URI the redirect should go to.
string   $protocol     Protocol to use when redirecting URIs.
integer   $port     A new port number.

[ Top ]

convertCharset   [line 651]

string convertCharset( string $from, string $to, string $str)

Convert the given string from one into another charset.

Uses mb_convert_encoding or iconv if available.

  • Return: converted string
  • Access: protected

Parameters:

string   $from     Source charset the string is in
string   $to     Target character set
string   $str     String to convert

[ Top ]

date   [line 55]

string|boolean date( [mixed $time = null])

Formats a RFC compliant GMT date HTTP header. This function honors the "y2k_compliance" php.ini directive and formats the GMT date corresponding to either RFC850 or RFC822.
  • Return: GMT date string, or FALSE for an invalid $time parameter
  • Access: public

Parameters:

mixed   $time     unix timestamp or date (default = current time)

[ Top ]

head   [line 331]

array head( string $url, [integer $timeout = 10])

Sends a "HEAD" HTTP command to a server and returns the headers as an associative array.

Example output could be:

  1.      Array
  2.      (
  3.          [response_code=> 200          // The HTTP response code
  4.          [response=> HTTP/1.1 200 OK   // The full HTTP response string
  5.          [Date=> Fri11 Jan 2002 01:41:44 GMT
  6.          [Server=> Apache/1.3.20 (UnixPHP/4.1.1
  7.          [X-Powered-By=> PHP/4.1.1
  8.          [Connection=> close
  9.          [Content-Type=> text/html
  10.      )

  • Return: Returns associative array of response headers on success
  • See: HTTP_Request
  • See: HTTP_Client::head()
  • Throws: InvalidArgumentException When the protocol is not uspported
  • Throws: HTTP2_Exception When connecting fails
  • Access: public

Parameters:

string   $url     A valid URL, e.g.: http://pear.php.net/credits.php
integer   $timeout     Timeout in seconds (default = 10)

[ Top ]

matchAccept   [line 254]

string|NULL matchAccept( string $header, array $supported)

Parses a weighed "Accept" HTTP header and matches it against a list of supported options
  • Return: a matched option, or NULL if no match
  • Access: protected

Parameters:

string   $header     The HTTP "Accept" header to parse
array   $supported     A list of supported values

[ Top ]

negotiateCharset   [line 157]

string negotiateCharset( array $supported, [string $default = 'ISO-8859-1'])

Negotiates charset with the user's browser through the Accept-Charset HTTP header.

Quality factors in the Accept-Charset: header are supported, e.g.: Accept-Language: en-UK;q=0.7, en-US;q=0.6, no, dk;q=0.8

  1.   require_once 'HTTP2.php';
  2.   $http = new HTTP2();
  3.   $charsets = array(
  4.       'UTF-8',
  5.       'ISO-8859-1',
  6.   );
  7.   $charset $http->negotiateCharset($charsets);

  • Return: The negotiated language result or the supplied default.
  • Author: Philippe Jausions <jausions@php.net>
  • Access: public

Parameters:

array   $supported     An array of supported charsets
string   $default     The default charset to use if none is found.

[ Top ]

negotiateLanguage   [line 101]

string negotiateLanguage( array $supported, [string $default = 'en-US'])

Negotiates language with the user's browser through the Accept-Language

HTTP header or the user's host address. Language codes are generally in the form "ll" for a language spoken in only one country, or "ll-CC" for a language spoken in a particular country. For example, U.S. English is "en-US", while British English is "en-UK". Portugese as spoken in Portugal is "pt-PT", while Brazilian Portugese is "pt-BR".

Quality factors in the Accept-Language: header are supported, e.g.: Accept-Language: en-UK;q=0.7, en-US;q=0.6, no, dk;q=0.8

  1.   require_once 'HTTP2.php';
  2.   $http = new HTTP2();
  3.   $langs = array(
  4.       'en'    => 'locales/en',
  5.       'en-US' => 'locales/en',
  6.       'en-UK' => 'locales/en',
  7.       'de'    => 'locales/de',
  8.       'de-DE' => 'locales/de',
  9.       'de-AT' => 'locales/de',
  10.   );
  11.   $neg $http->negotiateLanguage($langs);
  12.   $dir $langs[$neg];

  • Return: The negotiated language result or the supplied default.
  • Access: public

Parameters:

array   $supported     An associative array of supported languages, whose values must evaluate to true.
string   $default     The default language to use if none is found.

[ Top ]

negotiateMimeType   [line 207]

string negotiateMimeType( array $supported, string $default)

Negotiates content type with the user's browser through the Accept HTTP header.

Quality factors in the Accept: header are supported, e.g.: Accept: application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8

  1.   require_once 'HTTP2.php';
  2.   $http = new HTTP2();
  3.   $contentType = array(
  4.       'application/xhtml+xml',
  5.       'application/xml',
  6.       'text/html',
  7.       'text/plain',
  8.   );
  9.   $mime $http->negotiateMimeType($contentType);

  • Return: The negotiated MIME type result or the supplied default.
  • Author: Philippe Jausions <jausions@php.net>
  • Access: public

Parameters:

array   $supported     An associative array of supported MIME types.
string   $default     The default type to use if none match.

[ Top ]

parseLinks   [line 544]

array parseLinks( string|array $lines)

Parses a HTTP "Link" header value as specified by RFC 5988.

When errors occur during parsing, all information collected to that point will be returned used and the rest of the line skipped.

  • Return: Array of parsed links (one single line may contain multiple links) Only params existing in the link are in the array. URI is available in key "_uri".
  • Link: http://tools.ietf.org/html/rfc5988
  • Access: public

Parameters:

string|array   $lines     HTTP "Link:" header value (without "Link:"), or array of such strings

[ Top ]

redirect   [line 390]

boolean redirect( string $url, [bool $exit = true], [bool $rfc2616 = false])

This function redirects the client. This is done by issuing a "Location" header and exiting if wanted. If you set $rfc2616 to true HTTP will output a hypertext note with the location of the redirect.
  • Return: Returns TRUE on succes (or exits) or FALSE if headers have already been sent.

Parameters:

string   $url     URL where the redirect should go to.
bool   $exit     Whether to exit immediately after redirection.
bool   $rfc2616     Wheter to output a hypertext note where we're redirecting to (Redirecting to <a href="...">...</a>.)

[ Top ]

sortAccept   [line 276]

array sortAccept( string $header)

Parses and sorts a weighed "Accept" HTTP header
  • Return: Sorted list of "accept" options
  • Access: protected

Parameters:

string   $header     The HTTP "Accept" header to parse

[ Top ]


Documentation generated on Wed, 23 Oct 2013 18:00:03 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.