http://www.icyphoenix.com/viewtopic.php?f=4&t=2411&p=17314#p17314
-----------------------------------
casimedicos
Wed 04 Jul, 2007 00:19

Re: How To Prevent Hotlinking With PHP
-----------------------------------
For each piece of content create a file with the same name but with .php appended and place it in the same location as the content. This document should contain HTML (possibly with embedded PHP) to display when a site has either hotlinked or directly linked to yours. The simplest code will redirect the request to the page on your site containing the content:
[code linenumbers=false]<?php
header('Location: http://www.example.com/page-containing-the-content/');
?>[/code]

To include the content in your pages, use a URL of the form http://www.example.com/script-directory/?file=content-file, where &#8216;script-directory&#8217; is the directory containing the anti-hotlinking script, and &#8216;content-file&#8217; is the name of the content file (if the content file is in a subdirectory of the secret directory, include the subdirectory in the path &#8212; for example ?file=subdirectory/contentfile). These URLs can be included in the pages mentioned in the previous step in order to create a custom page displaying the content instead of redirecting to an existing page on your site. 
Now when someone tries to hotlink to content on your site, people visiting that page will only see the content if they have already been to your site. Direct links to content on your site will return an HTML file containing the content so you can ensure visitors see the file in its original context. 

The script currently includes MIME types for JPEG, PNG, WAV, and MIDI files. If you need to extend it to handle other file types, look up the MIME type name in the official list of MIME types and then add code of the following form above the line containing 'jpg'=>'image/jpeg',: 
    'extenstion'=>'mimetype',

&#8216;extension&#8217; is the file extension (for example, &#8216;mpg&#8217;) and &#8216;mimetype&#8217; is the official MIME type (for example, &#8216;video/mpeg&#8217;). Some formats do not have registered MIME types, in which case the x prefix should be used (for example, &#8216;image/x-myimageformat&#8217;).
http://www.iana.org/assignments/media-types/


