ar\http\headers
This module contains a number of methods to help with sending HTTP Headers. The methods here send these headers directly, they are not meant to be used with the ar_http::client
method.
methods
(bool) |
cache |
Controls whether the client (web browser) caches the page. |
(bool) |
content |
Sends a Content-Type header. |
(bool) |
disableCache |
Disables the client side cache. |
(string) |
getStatusMessage |
Returns a human readable message for a HTTP status code. |
(bool) |
header |
Sends a HTTP header. |
(bool) |
redirect |
Redirects the client (web browser) to another URL. |
(bool) |
sent |
Returns true if the headers have already been sent. |
(void) |
setStatusMessage |
Sets a human readable message for a HTTP status code. |
cache
(bool) ar_http_headers::cache( $expires = null, $modified = null )
(int) |
$expires |
Number of seconds untill the client side cache image must expire. If not set |
(int) |
$modified |
The unix timestamp for the last-modified date of this page. |
This method sends a number of headers, which together control the client side cache for most browsers and proxies. The headers are: 'Pragma: cache', 'Cache-control: public', 'Expires' and 'Last-Modified'.
The expires and last-modified headers can be skipped by setting the $expires
and / or $modified
values to false. The default expire time is 30 minutes from now, the default last-modified time is now.
The method returns true if it could send the headers, false otherwise.
content
(bool) ar_http_headers::content( $mimetype, $size = 0 )
(string) |
$mimetype |
The mimetype to send. |
(int) |
$size |
The content size, in bytes. |
Sends a Content-Type header with the given mimetype. Optionally sends a Content-Length header with the given size (unless $size
doesn't evaluate to true, e.g. 0 or false).
disableCache
(bool) ar_http_headers::disableCache( )
Sends a number of headers, which together disable client side caching for most browsers and proxies. The headers are: 'Pragma: no-cache', 'Cache-control: must-revalidate, max-age=0, private', 'Expires' and 'Last-modified'. The Expires timestamp is 1-1-1970, the Last-Modified timestamp is now.
getStatusMessage
(string) getStatusMessage( $code )
(int) |
$code |
The HTTP status code to get a human readable message for. |
This method returns a human readable message string for any known HTTP status code. e.g:
<pinp>
echo ar('http/headers')->getStatusMessage( 404 );
</pinp>
Prints out:
Not Found
header
(bool) ar_http_headers::header( $header )
(string) |
$header |
The HTTP header to send. |
Sends an HTTP header, unless the headers have already been sent. Returns true on success, false on failure.
redirect
(bool) ar_http_headers::redirect( $URI, $statusCode = 0 )
(string) | $URI | The location to redirect the browser to. |
(int) | $statusCode | Optional HTTP status code, e.g. 301. |
Sends a Location redirect header to the client (web browser). If a statusCode is given, it will also send a HTTP status header with the correct status code and message. e.g
<pinp>
ar('http/headers')->redirect( 'http://www.muze.nl/', 301 );
</pinp>
Will send the following headers:
HTTP/1.1 301 Moved Permanently
Location: http://www.muze.nl/
sent
(bool) sent( )
Returns true if the headers have already been send, false otherwise. If the headers have already been send, you cannot send any more headers.
setStatusMessage
(string) setStatusMessage( $code, $message )
(int) |
$code |
The HTTP status code to get a human readable message for. |
(string) |
$message |
The human readable message for the status code. |
This method sets a human readable message string for a HTTP status code.