Code:
//
// gzip_compression
//
$do_gzip_compress = FALSE;
if ( $board_config['gzip_compress'] )
{
$phpver = phpversion();
$useragent = (isset($_SERVER["HTTP_USER_AGENT"]) ) ? $_SERVER["HTTP_USER_AGENT"] : $HTTP_USER_AGENT;
if ( $phpver >= '4.0.4pl1' && ( strstr($useragent,'compatible') || strstr($useragent,'Gecko') ) )
{
if ( extension_loaded('zlib') )
{
ob_start('ob_gzhandler');
}
}
else if ( $phpver > '4.0' )
{
if ( strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') )
{
if ( extension_loaded('zlib') )
{
$do_gzip_compress = TRUE;
ob_start();
ob_implicit_flush(0);
header('Content-Encoding: gzip');
}
}
}
}
^ found this is PHPbb files (includes/page_header.php). The code goes right at the top before any output. Although that code is for PHPbb and can't just be stuck into something else.
However as other people have pointed out, its better to get the server software to do it.
To test if its working: access the page in Safari without the compression on and view the activity window - you can get the file sizes. Then turn compression off and try it. If it is working you should see a marked decrease in the file size for the main html document.
If you look here:
http://moodymonster.com/mgfs/index.php
the main index file is ~45K
the compressed version:
http://www.mobilegamefaqs.com/index.php
index file ~9K
Thats not using the PHP method though, its running through the server software but the principal is the same.
Though I'd try it using the PHP method by pasting:
ob_start("ob_gzhandler");
right at the top of the code, resulting file:
http://moodymonster.com/mgfs/index_gz.php
file size: ~9K