Source code for file /joomla/environment/response.php
Documentation is available at response.php
* @version $Id: request.php 5921 2006-12-04 16:12:21Z chrisdavenport $
* @package Joomla.Framework
* @subpackage Environment
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
* Create the response global object
$GLOBALS['_JRESPONSE'] =
new stdClass();
$GLOBALS['_JRESPONSE']->cachable =
true;
$GLOBALS['_JRESPONSE']->headers =
array();
$GLOBALS['_JRESPONSE']->body =
array();
* This class serves to provide the Joomla Framework with a common interface to access
* response variables. This includes header and body.
* @package Joomla.Framework
* @subpackage Environment
* Set/get cachable state for the response
* If $allow is set, sets the cachable state of the response. Always returns current state
* @return boolean True of browser caching should be allowed
$GLOBALS['_JRESPONSE']->cachable = (bool)
$allow;
return $GLOBALS['_JRESPONSE']->cachable;
* If $replace is true, replaces any headers already defined with that
* @param boolean $replace
function setHeader($name, $value, $replace =
false)
$value = (string)
$value;
foreach ($GLOBALS['_JRESPONSE']->headers as $key =>
$header) {
if ($name ==
$header['name']) {
unset
($GLOBALS['_JRESPONSE']->headers[$key]);
$GLOBALS['_JRESPONSE']->headers[] =
array(
* Return array of headers;
return $GLOBALS['_JRESPONSE']->headers;
$GLOBALS['_JRESPONSE']->headers =
array();
foreach ($GLOBALS['_JRESPONSE']->headers as $header)
// 'status' headers indicate an HTTP status, and need to be handled slightly differently
header($header['name'] .
': ' .
$header['value']);
* If body content already defined, this will replace it.
$GLOBALS['_JRESPONSE']->body =
array((string)
$content);
* Prepend content to the body content
* Append content to the body content
array_push($GLOBALS['_JRESPONSE']->body, (string)
$content);
* Return the body content
* @param boolean $toArray Whether or not to return the body content as an
* array of strings or as a single string; defaults to false
return $GLOBALS['_JRESPONSE']->body;
foreach ($GLOBALS['_JRESPONSE']->body as $content) {
* Sends all headers prior to returning the string
* @param boolean $compress If true, compress the data
// Don't compress something if the server is going todo it anyway. Waste of time.
if($compress &&
!ini_get('zlib.output_compression') &&
ini_get('output_handler')!=
'ob_gzhandler') {
JResponse::setHeader( 'Expires', 'Mon, 1 Jan 2001 00:00:00 GMT', true ); // Expires in the past
JResponse::setHeader( 'Cache-Control', 'no-store, no-cache, must-revalidate', true ); // Extra CYA
* Checks the accept encoding of the browser and compresses the data before
* sending it to the client.
* @return string compressed data
$level =
4; //ideal level
$gzdata = "\x1f\x8b\x08\x00\x00\x00\x00\x00";
$gzdata .= gzcompress($data, $level);
$gzdata = substr($gzdata, 0, strlen($gzdata) - 4);
$gzdata .= pack("V",$crc) . pack("V", $size);
* check, whether client supports compressed data
function _clientEncoding()
if (!isset
($_SERVER['HTTP_ACCEPT_ENCODING'])) {
if (false !==
strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
if (false !==
strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip')) {