Search code examples
videoembedhyperlinkrestriction

What are my options for preventing off-site linking for images/videos


At work I am building a form for uploading a user video and they want to include an option where you can specify if you want to allow your video to be embedded on another web site. Is there a way to prevent the video/image from being viewed and downloaded from another web site?

I've seen it happen with images when they are hosted somewhere and the account only has so much bandwidth allocated to it.

I don't even know how to tag this.


Solution

  • Yes you can. It depends at what level you want to limit the access. If all you want is to limit embedding from other websites (but don't mind that others can download the video anyway) a solution can be to watch the referer header.

    Something like this pseudo-code:

     $headers = getallheaders();
     $referer = $headers['Referer'];
    
     if( !checkReferer($referer) ){
        //don't admit, request coming from other website
     } else {
       //allow
     }
    

    Cheers!