Protect File CGI Scripts 4 U

A simple script for protecting your bandwidth from being used by other sites linking to your images. The script is called with the url

The script checks to see if the referer is valid, if it is then it displays the image as normal, otherwise it displays an 'dont steal my files' image. The script works with binary files such as zip and gzip files and can be used to hide email addresses, although not a perfect solution.

Note this script does NOT stop visitors from downloading images/files from your site and then upload them to their own, it just stops them from linking directly to your images.

Installation of the script is simple, Once you receive the tarball in your mailbox, upload it to your webserver and type tar -zxvf protectfiles.tar.gz

Edit the protectfile.cgi and set the 2 variables @referers and $datafile, next the only thing you need to do is edit the datafile (that $datafile points to), this file contains an id number, file path and mime type for each file being protected, with each file being on a seperate line in the file. Mime types that have been tested are:

  • binary/gzip - for gzip files
  • binary/zip - for zip files
  • text/html - for html files
  • image/gif - for gif images
  • image/jpeg - for jpeg images

We would expect other mime types to work in same way.

If you want to hide your email address from email harvesters you could enter it in data file in the format of id=email address=mail

The script always looks for an entry in the data file with an id of 9999 to use if the file is being accessed site not listed in the @referers variable so an entry must exist with an id of 9999.

Examples can be found in the datafile included in the tarball.

You should be ready to go.