Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Bandwidth Theft Prevention

    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.
    Code:
    //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

    Hope this is useful!

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Beyond Lament
    Posts
    424
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

    Code:
    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/";}
    Quíet Storm Designs ~ Art is not what you see, but what you make others see.
    · the Storms· || ·Ultraviolent Winter· || ·Was Einstein Wrong?· || ·It´s About Time!·


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •