how to Disable right click?

Discussion in 'PHP' started by black.hat, Dec 22, 2009.

  1. #1
    Some people are staling my website images,

    i know that its HARD to protect the images,

    But i am trying to disable the right click on the images ONLY
    Can anybody provide me a valid jquery code or PHP code that can do that?

    Please don't give me JavaScript code, i hate javascript,

    a simple HTML/jquery/PHP code that i can place my image within it will be fine

    Thanks
     
    black.hat, Dec 22, 2009 IP
  2. kingsoflegend

    kingsoflegend Well-Known Member

    Messages:
    202
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Quick question... what do you think the J in JQuery stands for?

    This can't be done in PHP and the JQuery solution (if someone bothered to write one) would most likely be overkill. Sorry but your best bet is to go with javascript.
     
    kingsoflegend, Dec 22, 2009 IP
  3. black.hat

    black.hat Active Member

    Messages:
    157
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Well i think its possible to do it with jquery,
    this site is done a similar solution with JQuery: http://davidwalsh.name/image-protector-plugin-for-jquery

    but i just failed to setup their code/plugin

    I don't know.. anyway do you think JavaScript will not make problems for my website?
    because actually my website is very well-designed and its codes are clear, i just don't want to damage it with stupid codes...

    Thanks
     
    black.hat, Dec 22, 2009 IP
  4. kingsoflegend

    kingsoflegend Well-Known Member

    Messages:
    202
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    108
    #4
    Like I said, using JQuery involves loading 1-2 libraries that are 30-40KB in size and the javascript solution is only a few lines of code. Personally I wouldn't want to load that much redundant code because it will slow down the site.

    I just googled how to do this in javascript and I've seen a prehistoric solution from the netscape days posted in several places. I did however find something very elegant:

    <body oncontextmenu="return false;">

    That's it. Much nicer than JQuery.
     
    kingsoflegend, Dec 22, 2009 IP
  5. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    there is no way to do that
    i mean there is no way to disable rightclick
    because if you disabiled
    any one will disable the java script from his explorer
    and right click

    you should make disable hot linking from your cp
     
    astkboy2008, Dec 22, 2009 IP
  6. kleinnico

    kleinnico Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Like astkboy says, disabling right click isn't the solution.

    Use .htaccess:
    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^[url]http://(.+\.)?domain\.com/[/url] [NC]
    RewriteCond %{HTTP_REFERER} !^$
    RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpe [L]
    Code (markup):
    Where /images/nohotlink.jpe is an image where it says they can't hotlink the images (use .jpe because otherwise it will block that image too!). Put your site also in that image and it might even give you some visitors.
     
    kleinnico, Dec 22, 2009 IP
  7. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    use flash gallery or somthing similar...
     
    xenon2010, Dec 22, 2009 IP
  8. Pirata Nervo

    Pirata Nervo Greenhorn

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #8
    Why disable right clicking?
    1st it's annoying
    2nd you can still copy/paste by viewing the source code of the page
    3rd it makes no sense to disable right clicking!

    Disable hotlinking is better
     
    Pirata Nervo, Dec 22, 2009 IP
  9. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #9
    I vote the simplest solution. It doesn't require javascript or php. It works with every browser and its backward compatible. It's called: Get over it.

    For one, there is no perfect or even adequate technological solution. For two, I am almost certain no one is making any money nor causing you any financial damage from said images. For three, its very easy to send a DMCA notice to the offending party--assuming of course they are violating the DMCA.
     
    plog, Dec 22, 2009 IP