1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Prevent hotlinking of images!

Discussion in 'HTML & Website Design' started by gedarnet, Jan 4, 2015.

  1. #1
    I have a site and blog, the pictures are stolen from them, I want a simple code to disallow of my files to view on other sites.
     
    gedarnet, Jan 4, 2015 IP
  2. jamjar919

    jamjar919 Well-Known Member

    Messages:
    332
    Likes Received:
    7
    Best Answers:
    5
    Trophy Points:
    180
    #2
    Do you mean that people are copy and pasting your images from your site? You can stop less technical users from stealing images by using a script that disallows right clicking, or covering images with a different element, though users may find these features annoying. You could also watermark your photos with your website address so people might not want to copy them.

    If you are instead referring to image "leeching" or "hotlinking", where other website owners use the image hosted on your site to serve it on their own (Like using an img tag with your web address as the src image), there are less solutions. One solution would to be to host your images on a different server and serve them from there instead, like uploading the images to imgur or a similar service. You could also use modifications to your .htaccess to prevent this. I used to use this solution but am unsure if it still works.
     
    jamjar919, Jan 4, 2015 IP
  3. gedarnet

    gedarnet Well-Known Member

    Messages:
    139
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #3
    (Do you mean that people are copy and pasting your images from your site?)
    (You could also use modifications to your .htaccess to prevent this.)

    Yeah.. I mean this ..
     
    gedarnet, Jan 4, 2015 IP
  4. Pigeon Yoga

    Pigeon Yoga Active Member

    Messages:
    52
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    63
    #4
    You can do this in nginx or apache (with .htaccess).
     
    Pigeon Yoga, Jan 4, 2015 IP
  5. gedarnet

    gedarnet Well-Known Member

    Messages:
    139
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #5
    How?
     
    gedarnet, Jan 4, 2015 IP
  6. ketting00

    ketting00 Well-Known Member

    Messages:
    772
    Likes Received:
    27
    Best Answers:
    3
    Trophy Points:
    128
    #6
    The most effective way I found is save it as base64 png image. Use PHP to save base64 string as png image. When you want to use the image just call it with base64_decode function.

    This way, image downloaded from your site will be useless for anyone with no clue. It doesn't prevent screen capture anyway.

    This topic on stackoverflow may give you some idea: How to save a PNG image server-side, from a base64 data string

    Sorry for not linking, I think some post with link has been taken off from this site.
     
    Last edited: Jan 5, 2015
    ketting00, Jan 5, 2015 IP
  7. gedarnet

    gedarnet Well-Known Member

    Messages:
    139
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #7
    Gorgeous, but is there an easy way in .htaccess?
     
    gedarnet, Jan 5, 2015 IP
  8. ketting00

    ketting00 Well-Known Member

    Messages:
    772
    Likes Received:
    27
    Best Answers:
    3
    Trophy Points:
    128
    #8
    I won't use .htaccess unless I want my site performance drop.

    If you use NGINX, there might be exception for that, but I don't know.

    By the way, I think PHP is far easy than .htaccess and without a nasty side effect.
     
    Last edited: Jan 5, 2015
    ketting00, Jan 5, 2015 IP
  9. Alexbizz

    Alexbizz Active Member

    Messages:
    195
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    60
    #9
    Cloudflare have also prevention of hotlinking images.
     
    Alexbizz, Jan 5, 2015 IP
  10. gedarnet

    gedarnet Well-Known Member

    Messages:
    139
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #10
    You sure?
     
    gedarnet, Jan 5, 2015 IP
  11. Alexbizz

    Alexbizz Active Member

    Messages:
    195
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    60
    #11
    Alexbizz, Jan 5, 2015 IP
  12. gedarnet

    gedarnet Well-Known Member

    Messages:
    139
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #12
    Something is not good in this plugin.
     
    gedarnet, Jan 5, 2015 IP
  13. Alexbizz

    Alexbizz Active Member

    Messages:
    195
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    60
    #13
    i am using cloudflare without security settings (because of that stupid captchas) but performance and optimizations are the best. And i am not using plugins, just add site to the cloudflare and change nameservers on domain register.
     
    Alexbizz, Jan 5, 2015 IP
  14. gedarnet

    gedarnet Well-Known Member

    Messages:
    139
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #14
    I just want to protect images by hotlinking..
     
    gedarnet, Jan 5, 2015 IP
  15. Alexbizz

    Alexbizz Active Member

    Messages:
    195
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    60
    #15
    Add your site on cloudflare.
    Change nameservers to point to cloudflare.
    Disable other options than Hotlink (this is under security settings).
     
    Alexbizz, Jan 5, 2015 IP
  16. Imgup

    Imgup Member

    Messages:
    67
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #16
    Or just use and external image host: http://imgup.io/ and embed the images on your site ;)

    Or, htaccess:

    
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
    RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
    
    Code (markup):
     
    Imgup, Jan 5, 2015 IP