HTACCESS Wrappers with PHP

Written by Robert Plank

Continued from page 1

$file = $_SERVER["PATH_TRANSLATED"]; readfile($file);



To makerepparttar 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. Atrepparttar 107755 very end it's all dumped into a function of your choosing whererepparttar 107756 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), compressesrepparttar 107757 data according torepparttar 107758 gzip standard and does allrepparttar 107759 header trickery that's needed to tellrepparttar 107760 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 throughrepparttar 107761 function ob_gzhandler() first. Put that atrepparttar 107762 top of our script and here's what we've got:

ob_start("ob_gzhandler"); $file = $_SERVER["PATH_TRANSLATED"]; readfile($file);


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. Without HTTP compression it took 5 and a half minutes to download. Withrepparttar 107763 compression, only 2 minutes. Internet Explorer told merepparttar 107764 download was going at 20 KB per second, impossible with a dialup connection... but sincerepparttar 107765 file was zipped, I really was downloading 20 KB a second (oncerepparttar 107766 data was decompressed on my end) over a 5 KB per second connection.

Though HTTP compression will work on sounds, video, and images,repparttar 107767 space you save is negligible, usually only a few bytes. These sorts of media are already heavily compressed so zipping makes almost no difference. This is why we've told htaccess to only use compression on text and HTML, because it's with human languages like English where a lot of repetition occurs, which means more information can be compressed.

Not all browsers support HTTP compression, but ob_gzhandler() figures out if a browser can support HTTP compression. Ifrepparttar 107768 browser doesn't,repparttar 107769 original file is displayed, no harm done.

You can get a copy of this sample script at: utorials/wrapper/

Both of these scripts I've created for you will work only on static files, files that actually exist such as images or HTML files. If you tried to apply these wrappers as-is to PHP scripts, Perl scripts or even HTML pages that use SSI. If your whole site is run by a single script it's a better idea to hard-code these things right in, anyway.


This last demonstration of an htaccess wrapper is something that I think most people with content sites have a use for. Onrepparttar 107770 Internet, people steal stuff. Theft of HTML source code is a nuisance, sure, butrepparttar 107771 lifting of images is more common. Someone likes a logo on your page, or an e-book cover, or a picture of a physical product you're selling, and it becomes theirs to use.

A practical way to keep this from happening is to add a watermark to all your images, which is your logo or name on a corner somewhere, forcing anyone who takes your graphic to either unwillingly give you credit, or chop off a part of that picture.

Lucky for us, PHP has a set of functions to handle images, and in version 4.3 and above, it's included by default. Wrappers come in handy here because you might have an entire site full of images and would rather not spend three weeks watermarking tons of images by hand. Maybe you just don't want to have to juggle two sets of images, one watermarked and one normal.

Download this script from: utorials/wrapper/

The only files you need to worry about in that zip are htaccess.txt and wrapper.php. Upload them to a folder called "watermark", chmod htaccess.txt to 0755 and rename to ".htaccess".

The file wrapper.php remain as is. I've put comments inrepparttar 107772 file regarding most of what it does, so if you're curious go ahead and take a peek.

Whatrepparttar 107773 script does is this: It figures outrepparttar 107774 original image that was supposed to be called. Then it loadsrepparttar 107775 watermark, which I've set in wrapper.php to be "watermark.png" which is just a PNG image containingrepparttar 107776 text "THIS IS WATER MARKED". The watermark is placed on top ofrepparttar 107777 original, inrepparttar 107778 lower right corner, and output inrepparttar 107779 same format (i.e., JPEG) asrepparttar 107780 original.

You can tellrepparttar 107781 difference by looking at these two images: utorials/wrapper homas.jpg utorials/wrapper homas-watermarked.jpg

I've included several types of images (GIFs, JPGs, and PNGs) inrepparttar 107782 zip file for you to test out. Once you've got everything setup, upload those images and see how they look withrepparttar 107783 watermark.

This script will work with GIFs, JPEGs, and PNGs. Due to a patent issue (which expires worldwide in July 2004) GIFs can only be read, and not output. To make up for this, any of your GIFs will be output as PNGs, which should still work.


If you think about it, a watermark script like this could also be used for a number of things. For example, if you decide to run an image hosting service like AuctionWatch does for eBay users, you could watermark your site's URL torepparttar 107784 bottom. Your users get a free service and everyone else sees a possible place to get free image hosting, there's some nice viral promotion right there.

You could also adaptrepparttar 107785 script to checkrepparttar 107786 HTTP referer (inrepparttar 107787 variable $_SERVER["HTTP_REFERER"]) to see ifrepparttar 107788 image was called offsite. If it was,repparttar 107789 script would putrepparttar 107790 watermark on there but if you called it from a page on your own site,repparttar 107791 image would be shown without one.

Even I have put wrappers to good use. Last year I wrote a product for Teresa King called Codewarden, which uses htaccess wrappers to display allrepparttar 107792 files of a directory in an encoded JavaScript string in an effort to hide HTML source.

Robert Plank is the creator of Lightning Track, Redirect Pro, Rotatorblaze, and other useful tools.

Want to pick up more programming skills? Then purchase the e-book "Simple PHP" at

You may reprint this article in full in your newsletter or web site.

Hard Drive Selection

Written by J A Carpunky

Continued from page 1

Now forrepparttar transfer rates you're going to need to do some searching,repparttar 107754 best way to find these numbers is to go torepparttar 107755 manufacturer's website and look at specification sheet forrepparttar 107756 model you're looking to buy (actually this isrepparttar 107757 best way to get allrepparttar 107758 information I've talked about so far). One thing to look out for is that you may read something that says 133MB/s or ATA/133 or SATA150 or 150MB/s, and these are notrepparttar 107759 numbers you are looking for, those numbers describerepparttar 107760 bus connectingrepparttar 107761 hard drive torepparttar 107762 motherboard, and are theoretical peak numbers, which tell us virtually nothing. Also, if you are buying a Maxtor, don't bother looking up actual transfer rates, as Maxtor is apparently afraid to release such information. Not to say Maxtor's are bad drives, actually Maxtor has risen torepparttar 107763 top in terms of technical support and they are much more willing to replace broken drives than some other companies, which is important since some ridiculously large amount (something like 10 or 15%) of hard drives are either dead on arrival or die withinrepparttar 107764 first few weeks of use. As withrepparttar 107765 last two points, when looking at transfer speeds (if you can find them) always try to pickrepparttar 107766 one withrepparttar 107767 highest numbers you can afford.

Notice thatrepparttar 107768 first three ofrepparttar 107769 4 major aspects were all speed related? That was done intentionally to give you a sense ofrepparttar 107770 importance of speed inrepparttar 107771 hard drive, because they are very very slow creatures, and for your gaming experience you don't need an enormous hard drive so much as a fast one. To increase speed substantially more you can set up a RAID, which is a network of hard drives which (in RAID0 mode) share portions ofrepparttar 107772 same data, such that accessing data takes 1/n time (n = number of hard drives attached) compared to 1 hard drive. To do this you really need a hardware RAID chipset, which are commonly included on higher-end mainboards.

Finally, capacity is an unnecessary nicety. The smallest hard drives you can buy today that are still within those higher speed classes are all about 30GB, which is more than enough for your games. But since games are not everything, and if you happen to be an iTunes member or like to download anime then you will really want some extra space. So I would recommend getting something between 60 and 120GB, any more and you're going to be paying through your teeth, any less and you might be looking to buy a supplementary hard drive in a couple years. And, oh yeah, 300GB hard drives from Maxtor are out, but they are comparatively slow, so I wouldn't recommend getting one for gaming, I like to stick to single platter drives (40-100GB usually), as they produce less heat and are less likely to break down on me.

That is really all you need to know in order to make a good choice when upgrading your hard drive or buying one for a new computer. Of course there are many other resources onrepparttar 107773 web if you would like more detail onrepparttar 107774 inner working of hard drives. For more information visit htp://

    <Back to Page 1 © 2005
Terms of Use