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

Class: HTTP

Source Location: /HTTP-1.4.1/HTTP.php

Class Overview


Miscellaneous HTTP Utilities


Author(s):

Version:

  • Release: $Revision: 1.56 $

Methods


Inherited Variables

Inherited Methods


Class Details

[line 44]
Miscellaneous HTTP Utilities

PEAR::HTTP provides static 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 446]

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 ]

Date   [line 57]

mixed 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 336]

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 or PEAR error on failure.
  • See: HTTP_Request
  • See: HTTP_Client::head()
  • Access: public

Parameters:

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

[ Top ]

negotiateCharset   [line 160]

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 'HTTP.php';
  2.   $charsets = array(
  3.       'UTF-8',
  4.       'ISO-8859-1',
  5.   );
  6.   $charset HTTP::negotiateCharset($charsets);

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

Parameters:

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

[ Top ]

negotiateLanguage   [line 104]

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 'HTTP.php';
  2.   $langs = array(
  3.       'en'    => 'locales/en',
  4.       'en-US' => 'locales/en',
  5.       'en-UK' => 'locales/en',
  6.       'de'    => 'locales/de',
  7.       'de-DE' => 'locales/de',
  8.       'de-AT' => 'locales/de',
  9.   );
  10.   $neg HTTP::negotiateLanguage($langs);
  11.   $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 209]

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 'HTTP.php';
  2.   $contentType = array(
  3.       'application/xhtml+xml',
  4.       'application/xml',
  5.       'text/html',
  6.       'text/plain',
  7.   );
  8.   $mime HTTP::negotiateContentType($contentType);

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

Parameters:

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

[ Top ]

raiseError   [line 541]

object PEAR_Error raiseError( [mixed $error = null], [integer $code = null])

Raise Error

Lazy raising of PEAR_Errors.

  • Access: protected

Parameters:

mixed   $error   —  Error
integer   $code   —  Error code

[ Top ]

redirect   [line 395]

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.
  • Access: public

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 ]


Documentation generated on Mon, 11 Mar 2019 15:25:21 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.