Get Image PHP Script

This is a script to stop leechers stealing images from your server. Designed for those who have limited bandwidth and don't want to waste it decorating somebody else's web site.

Instead of linking to images directly, you link through the script, which upon request will verify that the referrer (the requesting web-site) is yours, or blank (optional).

Download

The script is available in a zip file that contains the script and example HTML pages.

php_get_image.zip (26kb)

Using this Script

The following explains how to use this script on your own site:

See the sample file for a working example.

Note: Images do not need to be in a public location on the server, just so long as PHP can access them.

Options

$image_path

Tells the script where to get the images from. The parameter is relative to the location of the script.

The image directory does not need to be publicly accessible from the web server, it can be in any location that PHP can access. You can use ../ to access parent directories but note that ../ cannot be used in the filename parameter.

$file_field

Specifies the name of the parameter to get the filename from.

For example, in the default configuration, this is set to 'f', so you would use 'get_image?f=filename.jpg'. If you changed it to 'file' then you would ues 'get_image?file=filename.jpg'. This parameter is case sensitive.

$denied_file

Specifies the file to use when a request comes from a non-allowed source.

$allowed_refs

Specifies which referers are valid. You can specify as many referers as you wish, just separate them with commas like below.

$allowed_refs = array ( "www.website1.com", "www.website2.com", "www.website3.com" );

$allow_blank

Specifies whether an image should be shown when there isn't a referer present. I recommend setting this to true (default) as some users have their browser/personal firewall set to block the referring URL.