PDA

View Full Version : Bandwidth Theft Prevention


jscript_junkie
07-27-2002, 07:36 AM
Hey all.
I found this on JavaScriptKit. It checks to see if the site accessing the data is your domain. I found it pretty cool.

//Beginning of "test.js" file
var accepted_domains=new Array("wsabstract.com","javascriptkit.com")

var domaincheck=document.location.href //retrieve the current URL of user browser
var accepted_ok=false //set acess to false by default

if (domaincheck.indexOf("http")!=-1){ //if this is a http request
for (r=0;r<accepted_domains.length;r++){
if (domaincheck.indexOf(accepted_domains[r])!=-1){ //if a match is found
accepted_ok=true //set access to true, and break out of loop
break
}
}
}
else
accepted_ok=true

if (!accepted_ok){
alert("You\'re not allowed to directly link to this .js file on our server!")
history.back(-1)
}

/////rest of your libray
"
"
"


The JavaScriptKit page containing this is at this address (http://www.javascriptkit.com/javatutors/externalrestrict.shtml)

Hope this is useful! :D

Quiet Storm
08-01-2002, 06:33 PM
That's cool!

I changed the code a bit, so that instead of the browser going back a page, it just redirects to my site! :)


var accepted_domains=new Array("angelfire.com/mo2/cbch21/")
var domaincheck=document.location.href
var accepted_ok=false
if (domaincheck.indexOf("http")!=-1){
for (r=0;r<accepted_domains.length;r++){
if (domaincheck.indexOf(accepted_domains[r])!=-1){ //if a match is found
accepted_ok=true
break
}}}
else
accepted_ok=true
if (!accepted_ok){
alert("This site is not allowed to directly link to our files! \nRedirecting to Springfield DX")
document.location="http://angelfire.com/mo2/cbch21/";}