Preventing People From Leeching Your Images!

This tutorial will demonstrate how you can prevent other people from displaying YOUR images on their websites.

By this I mean people actually loading images on their site, from your website. This is a big problem is it will increase the bandwidth used on your account and therefore increasing your expenses. Many of you have seen the same thing in you use AngelFire free hosting. If you have an account with them and you want to display your image:

 

Now, unless the image is being called from within the AngelFire system, you get an ugly image saying "We're sorry, this image is hosted by AngelFire". Creating a system that does this is fairly easy in ColdFusion. Let me show you how it's done.

Now before I get to the explanation, some of you might be saying, wait a minute.. what do you mean? I've never used AngelFire...

So, I'll explain by showing, in the past when you wanted to display your images you used the standard:

	My Logo

The problem with this is that people would view your source or right click on the image and see the direct path to your image. This could be a problem, specially if you don't want your image to be displayed on other places by having it be loaded from your server. Anyone out there could simply use:

 
	My Logo

This could cost you lots of money, specially if it's a very popular image :)

Your alternative? This tutorial...

You can now load your images as follows:

 
	My Logo

Pretty nifty, huh? ok, let me explain what you must do to achieve this... the first thing we need to do is to create a file called: load_image.cfm

 
	<!--- File load_image.cfm --->
	<!--- First define the PHYSICAL path to the images --->
	<cfset images_path = "C:\inetpub\wwwroot\mysite.com\images\" />

The image path above will be where all the images are stored, the beauty of this script is that the images can even be in a folder that is NOT internet accessible.

 
	<!--- The next thing we do is verify that the image is being loaded from our site, and not someone else's --->
	<cfif NOT CGI.REFERER contains "mysite.com">
		<!--- Someone is trying to load this image from another place, stop them! --->
		<!--- The first thing we MUST do is load the smaller/error message file --->
		<cfcontent type="image/gif" file="#images_path#noleech.gif" />
		
	<cfelse>
		<!--- image is good, server the content --->
		<cfif Right(Image, 3) eq "gif">
			<cfcontent type="image/gif" file="#images_path##Image#" />
		<cfelseif Right(Image, 3) eq "jpg">
			<cfcontent type="image/jpg" file="#images_path##Image#" />
		</cfif>
	</cfif>

OK, what the code above is doing is basically this:

  • First, check to make sure that the image being called is coming from YOUR site and not someone else's.
    • If the call IS coming from your site, then it loads the image required and servers it to the calling web page.
    • If the call IS NOT coming from your site, it will load a different (SMALLER) image, therefore saving you bandwidth and not allowing that individual to load the image from their site.
  • The next thing is does is basically output the image. So that the page calling it will display it correctly.

Now on the pages you want the images to display you basically do this:

 
	
My Image Caption

this will ONLY work if it is being loaded from your web site, so if people view the source on the page, they will see this and not the actual path to the image itself.

NOTE: If you don't have an image to display when people are trying to steal your content, try this one:


To save right-click on it and save to your computer.

 
	<!---
		Notice that this image is being served as follows:
http://66.92.207.195/load_image.cfm?Image=noleech.gif --->

Need Another possible use for this tutorial?

Maybe if some of you want to know how many times an image was loaded. You could use this script to implement a counter system for your images. Remember that you have a .CFM page loading the image, so you could do anything you wanted right before serving the image. :-)

Well, That's pretty much it... Remember, this script will NOT stop people from downloading the images to their hard drives (That's pretty much impossible) but by hiding the paths to your images, people cannot load your images on their sites, using your bandwidth.

Questions? Comments? Email Me...

All ColdFusion Tutorials By Author: Pablo Varando
Download the EasyCFM.COM Browser Toolbar!