NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page Protect your flash files from hotlinking - specially for arcade sites!

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 07-14-2005, 05:50 PM THREAD STARTER               #1 (permalink)
NamePros Regular
 
Jim_Westergren's Avatar
Join Date: May 2005
Location: Sweden
Posts: 730
Jim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to behold
 




Protect your flash files from hotlinking - specially for arcade sites!


This article is written to those who have tried to find a solution on how to prevent people from using up your bandwidth of flash files.
????: NamePros.com http://www.namepros.com/code/106681-protect-your-flash-files-hotlinking-specially.html

Almost everybody who are making web sites knows that you can easily display images and even flash files from other sites simply by writing the URL:

<embed src="http://www.yoursite.com/swf/yourflashfile.swf"></embed>

You have perhaps also realised this and tried to hide your URL from being viewed. Maybe you inserted a javascript that made it impossible to right click only to find out that you can easily click on View -> Source in the menubar. Then maybe you made with the help of javascript that the flash file opens in a new window with turned off right click and with no menubar. When you then found out that you can simply click on SHIFT + F10 -> View source you maybe took one step further. You made the flash file open up in an iframe that had the exact size as the flash file but you probably realized that you can simply see the source URL in the code and open up that in the browser and then find the URL of the flash file.

You looked on other solutions and you maybe saw those programs that maybe costed hundreds of dollars that made it possible to encrypt the flash files. You looked at it a while, saw the work of it, your thin wallet and went in apathy about the whole thing and skipped it. “It’s cheaper to pay my webhosting the stolen bandwidth than those programs”, maybe you thought.

Now recently I have found a new solution that is very simple, good, works and is free.

Let’s say you have your flash files in a directory called swf and on your index.html the flash file opens.

Step 1:

Create a file called .htaccess in your swf directory (if windows refuses to change the file locally change it when you have uploaded it with your FTP program.)

Cut and paste the following lines (change “nameofyourdomain”):
Code:
Options +FollowSymLinks
RewriteEngine on

RewriteOptions inherit
RewriteCond %{HTTP_REFERER} !^http://([a-z0-9-]+\.)* nameofyourdomain.com/ [NC]
RewriteCond %{HTTP_COOKIE} !(^|(.+;)*)id=valid(;.*|$)
RewriteRule /*$ http://www.nameofyourdomain.com/copy.html [L,R]
It is the last 3 lines that are important here and I will explain them here in simple english:

1. If the request is not coming from your own domain.
2. Or if there is no cookie.
3. Redirect to copy.html

On other guides on the internet you will find the above but without the second last line. Without the second last line it works perfectly in Firefox but in Internet Explorer the flash file will not load on your own site. The solution to this is the cookie.

Step 2:

Insert the following in the HEAD of your index.html (or the file in which you have the flash file):
Code:
<SCRIPT LANGUAGE="javascript">
// Calculate the expiration date
var expires = new Date ();
expires.setTime(expires.getTime() + 1 * 1 * 20 * 60);
document.cookie = "id=valid; path=/" + "; expires=" + expires.toGMTString();
</SCRIPT>
This will make a cookie when the visitor comes to the site and if the cookie exist internet explorer will load the flash file. Now if you see the above you will see that the cookie will expire very fast, like in 2 seconds or something. The time is just enough for internet explorer to start to load the flash file and way to short for the stealer to find the URL and try to download it.
????: NamePros.com http://www.namepros.com/showthread.php?t=106681

If now the stealer goes to your site, copies the URL and writes it in the browser, guess what will happen, he will be directed to copy.html and there you can write a surprise for him! If he makes a link to your flash URL on a local html file, right clicks to “save target as ...”, guess what he will download, the copy.html file with the surprice!

Hotlinking also doesn’t work as there is no cookie and the flash file simply will not load.

This method works both in Internet Explorer and Firefox.

Good luck.

Copyright © 2005 Jim Westergren
__________________
Jim Westergren
www.JimWestergren.com / Free website with N.nu
Jim_Westergren is offline  
Old 07-15-2005, 01:12 AM   #2 (permalink)
NamePros Member
 
kingeric's Avatar
Join Date: Feb 2005
Posts: 96
kingeric will become famous soon enough
 



Thanks for the tip...but I just went to yer site and I can't play any of your games...I get a blank sceen. You might want to check it out. You might be losing some of your legit players.
kingeric is offline  
Old 07-15-2005, 03:21 AM THREAD STARTER               #3 (permalink)
NamePros Regular
 
Jim_Westergren's Avatar
Join Date: May 2005
Location: Sweden
Posts: 730
Jim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to behold
 




Really!?

That's bad. Maybe you have cookies disabled and run on IE?

You are right, it is risky and I have disabled it for now. Have to modify it so that it works better.

I thought I had such a good solution but, well.

Maybe someone here knows a how to modify it so it works for ALL users?

Thanks.
__________________
Jim Westergren
www.JimWestergren.com / Free website with N.nu
Jim_Westergren is offline  
Old 07-15-2005, 04:08 AM   #4 (permalink)
NamePros Member
 
kingeric's Avatar
Join Date: Feb 2005
Posts: 96
kingeric will become famous soon enough
 



I'm running the standard configuration for IE which is the same as 90 percent of all IE users. My cookies are enabled.
kingeric is offline  
Old 07-15-2005, 05:28 AM THREAD STARTER               #5 (permalink)
NamePros Regular
 
Jim_Westergren's Avatar
Join Date: May 2005
Location: Sweden
Posts: 730
Jim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to beholdJim_Westergren is a splendid one to behold
 




I give 20 NP$ to the one that solves this and PMs me the solution. It just has to prevent hotlinking of the flash files and work for all visitors regardless of browser and cookie settings. Prevention of copy is just a bonus.

I will be gone for 7 days so I won't have access to the forum but will pay once I am back.

Thanks.
__________________
Jim Westergren
www.JimWestergren.com / Free website with N.nu
Jim_Westergren is offline  
Old 07-15-2005, 07:23 AM   #6 (permalink)
Senior Member
Join Date: Mar 2004
Posts: 1,402
primacomputer is a jewel in the roughprimacomputer is a jewel in the roughprimacomputer is a jewel in the rough
 



Protecting against someone saving the file to their local drive is, by definition, impossible to do and still let them play the flash game. They can simply save the entire page and pull the swf out the the page_files folder. They could also pull the file out of their cache. Someone who wanted to rape your site could simply use something like wget with the --referrer option. The only way to stop people from running flash files from their local drive (or another location) is to add some logic to the flash that will cause it to not run unless certain criteria are met. Copy protection for a flash file. Who woulda though it would come to this.

Preventing hot linking is a bit more functional, but there is nothing to stop someone from wrapping an iframe inside a layer on effectively creating a window from their site through to the game on your site. You need to replace your index.html with some sort of script to even start to deal with that.

I have a site that is constantly under attack by leachers and sometimes just gets bombarded by hits from blogs, forums, etc. I came up with a solution that is pretty complicated but might be something you could adapt for your needs. With my system files are never served directly by the web server. They are served by a script that reads them from another part of the file system and outputs the appropriate HTTP headers and data for each request. It works a lot like your htaccess rules in that it returns different data based on certain things but since it's a script it's dynamic and can change it's behaviour based on a complex set of rules.

The main benefit of this is that you can start with few restrictions and tighten them up as you go. You start by serving the media to anyone, but when you get 50 deep link from the same host in one hour you can simply stop serving the media to clients being referred by that host. You don't have to worry about making a set of rules that work for every user+browser+network combination because the rules only kick in when there is anomalous activity.
primacomputer is offline  
Old 07-15-2005, 03:22 PM   #7 (permalink)
NamePros Regular
Join Date: Feb 2005
Location: UK
Posts: 409
Oblivion. is a jewel in the roughOblivion. is a jewel in the roughOblivion. is a jewel in the rough
 



This is something I've been playing around with for the last few days, as part of a new site I'm making. I thought I'd got it the other day, until I went to use my site in IE and it just gave me the wrong file . I'll donate 20NP$ to anyone that can make a fully working solution.
????: NamePros.com http://www.namepros.com/showthread.php?t=106681

*EDIT*

HTML Code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://arcaderival.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://arcaderival.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.arcaderival.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.arcaderival.com$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|swf|dcr)$ http://www.arcaderival.com/ar_120_600.swf [R,NC]
That seems to be working for me .
Last edited by Oblivion.; 07-15-2005 at 03:41 PM.
Oblivion. is offline  
Old 07-15-2005, 11:19 PM   #8 (permalink)
Senior Member
Join Date: Mar 2004
Posts: 1,402
primacomputer is a jewel in the roughprimacomputer is a jewel in the roughprimacomputer is a jewel in the rough
 



Well if you're using it on your site now then it doesn't work because just embedded a link to sonic on your server in a web page on my server and it played fine.
primacomputer is offline  
Old 07-16-2005, 10:05 AM   #9 (permalink)
NamePros Regular
Join Date: Feb 2005
Location: UK
Posts: 409
Oblivion. is a jewel in the roughOblivion. is a jewel in the roughOblivion. is a jewel in the rough
 



Originally Posted by primacomputer
Well if you're using it on your site now then it doesn't work because just embedded a link to sonic on your server in a web page on my server and it played fine.
Please can you tell me the URL to the file you embeded...
Oblivion. is offline  
Old 07-16-2005, 11:07 PM   #10 (permalink)
Senior Member
Join Date: Mar 2004
Posts: 1,402
primacomputer is a jewel in the roughprimacomputer is a jewel in the roughprimacomputer is a jewel in the rough
 



The URL that has embedded file is this:
http://ptdt.com/lib/arcaderival_embed.asp

It appears to be serving up different content without the correct referrer now. The main problem seems to be with the browser cache. If you have already downloaded the swf file then the browser will not try to download it again and it will play fine. This means all I'd need to do is create a “loading” page that has a tiny iframe of your page with the swf. Once it is loaded into cache I can display my page with the file embedded from your server and it will run.

Try it. Start up a fresh browser session, clear your cache, and visit my URL. You get served the alternative flash file. Then visit your site (http://arcaderival.com/index.php?act=play&id=219) let the game load. Then go back to the URL on my site. It will run fine.
????: NamePros.com http://www.namepros.com/showthread.php?t=106681

Also, for an example of how you can clip any section of another site and display it in your own have a look at this:
http://ptdt.com/lib/arcaderival_frame.asp
primacomputer is offline  
Old 07-17-2005, 08:17 AM   #11 (permalink)
NamePros Regular
Join Date: Feb 2005
Location: UK
Posts: 409
Oblivion. is a jewel in the roughOblivion. is a jewel in the roughOblivion. is a jewel in the rough
 



Damn, that's.... not good I've got a feelnig there wouldn't be any easy way to stop someone from doing that, thanks for making those examples to show me what you meant though .
Oblivion. is offline  
Old 07-17-2005, 10:00 AM   #12 (permalink)
Senior Member
Join Date: Mar 2004
Posts: 1,402
primacomputer is a jewel in the roughprimacomputer is a jewel in the roughprimacomputer is a jewel in the rough
 



It's not the end of the world. You can stop this by making restrictions based on the referrers to the page in which you have embedded the flash file. You want to leave this as unrestricted as possible so that people can bookmark the page, visit it from search engines, etc. If someone frames this you will see a huge number of referrers from their site. Just watch for this and deal with it on a case by case basis.
primacomputer is offline  
Old 07-17-2005, 10:14 AM   #13 (permalink)
NamePros Regular
Join Date: Feb 2005
Location: UK
Posts: 409
Oblivion. is a jewel in the roughOblivion. is a jewel in the roughOblivion. is a jewel in the rough
 



Originally Posted by primacomputer
It's not the end of the world. You can stop this by making restrictions based on the referrers to the page in which you have embedded the flash file. You want to leave this as unrestricted as possible so that people can bookmark the page, visit it from search engines, etc. If someone frames this you will see a huge number of referrers from their site. Just watch for this and deal with it on a case by case basis.
I've done that previously with a few sites
Oblivion. is offline  
Old 07-17-2005, 11:03 AM   #14 (permalink)
Senior Member
Join Date: Mar 2004
Posts: 1,402
primacomputer is a jewel in the roughprimacomputer is a jewel in the roughprimacomputer is a jewel in the rough
 



Perhaps return a page that redirects to the page they are framing, with a _top which will remove their site and take the user to the page on your site the other guy is trying to leach. A great way to get unscrupulous competitors to send you free traffic.
primacomputer is offline  
Old 07-17-2005, 11:08 AM   #15 (permalink)
NamePros Regular
Join Date: Feb 2005
Location: UK
Posts: 409
Oblivion. is a jewel in the roughOblivion. is a jewel in the roughOblivion. is a jewel in the rough
 



That's a good idea! When I next see someone leeching, I'll do that for a few days
Oblivion. is offline  
Old 08-29-2005, 02:42 PM   #16 (permalink)
NamePros Regular
Join Date: Jul 2005
Location: Vancouver
Posts: 533
shadow_boi is a jewel in the roughshadow_boi is a jewel in the roughshadow_boi is a jewel in the rough
 



who tried it already? i want to test it
shadow_boi is offline  
Closed Thread


LinkBacks (?)
LinkBack to this Thread: http://www.namepros.com/code/106681-protect-your-flash-files-hotlinking-specially.html
Posted By For Type Date
protect video files - SitePoint Forums This thread Refback 07-12-2011 08:23 PM
Casey McKinnon and Rudy Jahchan against CanCon Net regulations &#8211; Christian Aubry | Web + Vidéo = Communication @ Montréal, Qc This thread Refback 06-22-2011 10:41 AM
apache2 - Apache 2: Prevent image hotlinking serverwide - Server Fault This thread Refback 01-12-2011 01:50 PM
Recent flash Bookmarks on Delicious This thread Refback 12-28-2009 11:24 PM
Apache 2: Prevent image hotlinking serverwide - Server Fault This thread Refback 06-03-2009 05:54 PM
Razorberry's Adobe Flash Blog » Blog Archive » Protecting your SWF This thread Refback 05-02-2009 06:12 AM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Totorial - Adding Music to your Site abacomedia Webmaster Tutorials 7 08-27-2005 09:12 AM
Flash Deadly Sins (that can kill your web business) abacomedia Graphic Design / Flash 2 06-26-2004 10:32 PM
Using Music on your Site - WAV, MP3, MIDI, Flash? abacomedia Web Design Discussion 1 05-20-2004 02:04 PM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 02:13 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger