HTACCESS Wrappers with PHP - If our wrapper...
(Page 5 of 9 )
If our wrapper were simply going to pass through the file (in other words, just read its contents into a variable and display it), our handler script would look like this:
"GIFT WRAPPING" YOUR OUTPUT
To make the HTTP compression work, we use two functions: ob_start() and ob_gzhandler(). Output buffering functions are strange. Any time you try to display something, you can have PHP save up everything you're trying to output. At the very end it's all dumped into a function of your choosing where the text can be changed or transformed before it's output.
There is a built-in PHP function called ob_gzhandler() which takes one parameter (a string of text), compresses the data according to the gzip standard and does all the header trickery that's needed to tell the user's browser that we are transmitting data that needs to be decompressed once it's downloaded. When this line is used:
It tells PHP: everything displayed afterwards has to go through the function ob_gzhandler() first. Put that at the top of our script and here's what we've got:
Save that as compress.php. Upload both files, chmod htaccess.txt to 0755 and rename to .htaccess and you're done. That's all you need for it to work, and you can just as easily apply HTTP compression to any script by just adding that line.
To try this puppy out, I got on a dialup connection and put a copy of "The Decline And Fall Of The Roman Empire Volume 1" on my web host, a 900 page book, about 1.6 megabytes in size.
More Web Development Articles
More By 359