<?php
/**
* Dynamic Content Acceleration compresses
* the data transmission data on the fly
* code by sun jin hu (catoc) <hide@address.com>
* Most newer browsers since 1998/1999 have
* been equipped to support the HTTP 1.1
* standard known as "content-encoding."
* Essentially the browser indicates to the
* server that it can accept "content encoding"
* and if the server is capable it will then
* compress the data and transmit it. The
* browser decompresses it and then renders
* the page.
*
* Modified by John Lim (hide@address.com)
* based on ideas by Sandy McArthur, Jr.
*
* Modified and simplified by Tobias H. Michaelsen.
*
* Usage........:
* No space before the beginning of the first '<?php tag.
* ------------Start of file----------
* |<?php
* | include_once('gzdoc.php');
* |?>
* |<HTML>
* |... the page ...
* |</HTML>
* -------------End of file-----------
*
* @name PHP4 HTTP Compression Speeds up the Web
* @version 2
* @author catoc <hide@address.com>
* @author Tobias H Michaelsen <hide@address.com>
* @file gzdoc.php
* @changed 2001-10-16
* @require PHP4 >= 4.0.1
* PHP was configured with --with-zlib[=DIR]
*
* $Id: gzdoc.php,v 1.9 2001/10/16 02:45:16 zaiborg Exp $
*/
if (COMPRESS_OUTPUT and !DEBUG) {
if (function_exists('ob_gzhandler')) {
// This function is only available from PHP version 4.0.4
ob_start('ob_gzhandler');
} else {
ob_start('gzDocOut');
}
ob_implicit_flush(0);
}
function checkCanGzip()
{
global $HTTP_ACCEPT_ENCODING;
if (!function_exists('gzencode')) {
return false;
}
if (headers_sent() or connection_status() != 0) {
return false;
}
if (strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false) return "x-gzip";
if (strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false) return "gzip";
return false;
}
function gzDocOut($contents)
{
$encoding = checkCanGzip();
if ($encoding != false) {
if ($compressed = gzencode($contents)) {
header("Content-Encoding: $encoding");
return $compressed;
}
}
return $contents;
}
?>