Class HTTP_Headers

Description

HTTP Headers class

Class for holding HTTP headers. Used by the HTTP Request and Response classes.

See test_HTTP_Headers.php file for examples of how relative URLs are handled.

TODO:

  • none yet

Located in Program_Root/HTTP_Headers.php (line 37)


	
			
Method Summary
void HTTP_Headers ([array $headers = null])
array as_array ()
string as_string ()
array authorization_basic ([string $user = null], [string $pass = ''])
object &clone ()
string content_type ([string $string = null])
int date ([int $time = null])
int expires ([int $time = null])
array get_header_array (string $field, [int $limit = null])
string get_header_string (string $field, [int $limit = null])
void header_exists (string $field)
int if_modified_since ([int $time = null])
int if_unmodified_since ([int $time = null])
bool init_header (string $field, mixed $value)
int last_modified ([int $time = null])
array proxy_authorization_basic ([string $user = null], [string $pass = ''])
void push_header (string $field, mixed $value)
string range ([string $string = null])
string referer ([string $string = null])
void remove_header (mixed $field)
void scan (mixed $callback, mixed &$param)
void set_header (string $field, mixed $value)
void set_headers (array $headers)
string user_agent ([string $string = null])
Methods
Constructor HTTP_Headers (line 59)

Constructor

Optional parameter accepts an associative array of fields and values. Example:


1 $headers =& new HTTP_Headers(array(
2 'Content-Type' => 'text/plain',
3 'Date' => 'Thu, 03 Feb 1994 00:00:00 GMT'
4 ));

void HTTP_Headers ([array $headers = null])
  • array $headers:

    associative array holding field and value

as_array (line 160)

As array

Returns all headers to be used in a HTTP message. Array returned is indexed with the header key and value together. Example of returned array:

   [0] -> 'Range: bytes=0-99'
   [1] -> 'Connection: close'
 

array as_array ()
as_string (line 141)

As string - returns all headers to be used in a HTTP message.

Each header is seperated by a CRLF.

string as_string ()
authorization_basic (line 461)

Authorization: Basic

  • return:

    false if not found or invalid

array authorization_basic ([string $user = null], [string $pass = ''])
  • string $user
  • string $pass
clone (line 171)

Clone - return a copy.

object &clone ()
content_type (line 447)

Content-Type

string content_type ([string $string = null])
  • string $string
date (line 357)

Date

Accepts a unix timestamp integer to set the date, or returns the date as a unix timestamp if no argument is passed.

int date ([int $time = null])
  • int $time
expires (line 367)

Expires - see date()

int expires ([int $time = null])
  • int $time
get_header_array (line 256)

Get header array

Returns the header value(s) as an array

Example:


1 $cookies = $headers->get_header_array('Set-Cookie');

array get_header_array (string $field, [int $limit = null])
  • string $field
  • int $limit:

    specifies maximum number of headers to return (null = no limit (default))

get_header_string (line 278)

Get header string

Returns the header value (seperated by ', ' if there's more than one).

Example:


1 $date = $headers->get_header_string('Date');

string get_header_string (string $field, [int $limit = null])
  • string $field
  • int $limit:

    specifies maximum number of headers to return (null = no limit (default))

header_exists (line 189)

Header exists

Example: if ($headers->header_exists('content-type')) { echo 'Oh no!'; }

void header_exists (string $field)
  • string $field
if_modified_since (line 377)

If-Modified-Since - see date()

int if_modified_since ([int $time = null])
  • int $time
if_unmodified_since (line 387)

If-Unmodified-Since - see date()

int if_unmodified_since ([int $time = null])
  • int $time
init_header (line 316)

Init header

Set the specified header to the given value, but only if no previous value for that field is set.

  • return:

    true if value is set, false otherwise

bool init_header (string $field, mixed $value)
  • string $field
  • mixed $value:

    array holding values, or string holding a single value

last_modified (line 397)

Last-Modified - see date()

int last_modified ([int $time = null])
  • int $time
proxy_authorization_basic (line 472)

Proxy-Authorization: Basic

  • return:

    false if not found or invalid

array proxy_authorization_basic ([string $user = null], [string $pass = ''])
  • string $user
  • string $pass
push_header (line 298)

Push header

Add a new field value for the specified header field. previous values for the same field are retained.

Example:


1 $headers->push_header('Accept', 'image/jpeg');

void push_header (string $field, mixed $value)
  • string $field
  • mixed $value:

    array holding values, or string holding a single value

range (line 435)

Range

string range ([string $string = null])
  • string $string
referer (line 423)

Referer

string referer ([string $string = null])
  • string $string
remove_header (line 337)

Remove header

This function removes the header fields with the specified name(s).

void remove_header (mixed $field)
  • mixed $field:

    string to specify a single field, array to specify more than 1 field

scan (line 84)

Scan - goes through all headers passing the field and values through the callback function.

If a field has multiple values, each value will be passed seperately (not as an array).

The callback function can be a method from another object (eg. array(&$my_obj, 'my_method')). The callback function should accept 3 arguments:

  1. A reference to the headers object (&$headers)
  2. An array holding field name and value, array is associative with the following keys: 'field', 'value'
  3. An optional parameter which can be used for whatever your function wants :), even though you might not have a use for this parameter, you need to define your function to accept it. (Note: you can have this parameter be passed by reference)
The callback function should return a boolean, a value of 'true' will tell scan() you want it to continue with the rest of the headers, 'false' will tell scan() to not send any more headers to your callback function.

void scan (mixed $callback, mixed &$param)
  • mixed $callback:

    function name, or array holding an object and the method to call.

  • mixed $param:

    passed as the 3rd argument to $callback

set_header (line 232)

Set header

Adds value(s) to header overwriting any existing values.

Example:


1 $headers->set_header('Accept', 'image/jpeg');
2 $headers->set_header('Accept', array('text/html', 'text/plain', 'image/*'));
2

void set_header (string $field, mixed $value)
  • string $field
  • mixed $value:

    array holding values, or string holding a single value

set_headers (line 209)

Set headers

Add multiple headers and values.

Example:


1 $headers->set_headers(array(
2 'Content-Type' => 'text/plain',
3 'Date' => 'Thu, 03 Feb 1994 00:00:00 GMT',
4 'Accept' => array('text/html', 'text/plain', 'image/*')
5 ));

void set_headers (array $headers)
  • array $headers:

    associative array holding field and value

user_agent (line 411)

User-Agent

string user_agent ([string $string = null])
  • string $string

Documention generated on Wed, 16 Jul 2003 01:03:22 +0100 by phpDocumentor 1.2.0