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:
Located in Program_Root/HTTP_Headers.php (line 37)
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 ));
associative array holding field and value
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'
As string - returns all headers to be used in a HTTP message.
Each header is seperated by a CRLF.
Authorization: Basic
Date
Accepts a unix timestamp integer to set the date, or returns the date as a unix timestamp if no argument is passed.
Get header array
Returns the header value(s) as an array
Example:
1 $cookies = $headers->get_header_array('Set-Cookie');
specifies maximum number of headers to return (null = no limit (default))
Get header string
Returns the header value (seperated by ', ' if there's more than one).
Example:
1 $date = $headers->get_header_string('Date');
specifies maximum number of headers to return (null = no limit (default))
Header exists
Example: if ($headers->header_exists('content-type')) { echo 'Oh no!'; }
If-Modified-Since - see date()
If-Unmodified-Since - see date()
Init header
Set the specified header to the given value, but only if no previous value for that field is set.
array holding values, or string holding a single value
Last-Modified - see date()
Proxy-Authorization: Basic
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');
array holding values, or string holding a single value
Remove header
This function removes the header fields with the specified name(s).
string to specify a single field, array to specify more than 1 field
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:
function name, or array holding an object and the method to call.
passed as the 3rd argument to $callback
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
array holding values, or string holding a single value
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 ));
associative array holding field and value
Documention generated on Wed, 16 Jul 2003 01:03:22 +0100 by phpDocumentor 1.2.0