View Full Version : bandwith script
cunning-fox
08-15-2002, 01:29 AM
Hi,
I saw a bandwith prevention script for a .js file in this forum. Is it possible to make this suitable for a html file, if so, anyone?
http://www.codingforums.com/showthread.php?threadid=2796
This script would be of great use to me.
Thanks for any replies
cunning-fox
08-15-2002, 03:35 AM
Anyone think this is possible?
Quiet Storm
08-15-2002, 03:49 AM
It is possible.
Give it a couple of days, someone will figure it out - patience. :)
x_goose_x
08-15-2002, 03:59 AM
Wouldn't the script have the same results to a web page if placed in the page within "script" tags?
cunning-fox
08-15-2002, 04:17 AM
There was an error when I tried to do it "onload".
cunning-fox
08-15-2002, 02:01 PM
So I guess the question really is how would you use domain restrictions to keep people off an html page?
x_goose_x
08-15-2002, 03:46 PM
Try this here:
http://www.geocities.com/x_goose_x/testt.htm
this is the code for it, exactly as it was on the original post:
<script>
var accepted_domains=new Array("geocities.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)
}
</script>
Hello welcome to my geocities site.
BrainJar
08-15-2002, 04:22 PM
There are a couple of things that article overlooks.
One, some firewalls strip the HTTP referer header from requests. So legitimate requests can fail for some users.
Two, the JavaScript technique doesn't necessarily save bandwidth on your site. Browsers will still load the file. The code simply makes it execute differently when the referer doesn't match your site URL. Obviously, the idea is that most web masters who try linking to your script will notice a problem and remove the link, but you never know what some inexperienced page maker may do.
The .htaccess approach is better in that regard. It will actually prevent the file from being downloaded. Plus it will work for images and other file types as well. But again, some users behind firewalls could be adversely affected.
x_goose_x
08-24-2002, 02:31 AM
<script>
if (location.hostname!="www.geocities.com") {
alert("The site that has linke you to this is not authorized. You now will be forwarded to the original site");
location.replace("index.htm");
}
</script>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.