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.

How do i disable right click using PHP code?

Discussion in 'PHP' started by Jalpari, Aug 26, 2010.

  1. #1
    How do i disable the right click function in wp using PHP :p
     
    Jalpari, Aug 26, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    I think it is impossible because right click is client-side event and not server-side event, and PHP is server-side scripting language.
     
    s_ruben, Aug 26, 2010 IP
  3. Cyb3rgh0st_

    Cyb3rgh0st_ Greenhorn

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    why would u want to disable right click anyways lol ..
    and im sure u can get javascript for this . i may be wrong
     
    Cyb3rgh0st_, Aug 26, 2010 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    Javascript. But it's a pointless practice. It breaks a website's usability, and is easily circumvented. Does far, far, more harm than any possible good.
     
    jestep, Aug 26, 2010 IP
  5. Jalpari

    Jalpari Notable Member

    Messages:
    5,640
    Likes Received:
    137
    Best Answers:
    0
    Trophy Points:
    260
    #5
    Oh! good point, i just forget.

    I tried javascript but that is not the security since it can easily break.

    well said.
     
    Jalpari, Aug 26, 2010 IP
  6. canishk

    canishk Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You can successfully disable the right click by using jQuery.


    $(document).ready(function()
    { 
           $(document).bind("contextmenu",function(e){
                  return false;
           }); 
    });
    Code (markup):
     
    canishk, Aug 27, 2010 IP
  7. patrick24601

    patrick24601 Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If you disable the right click to hide your the menu options for viewing source is still enabled. Don't waste the time. Not a damn thing you can do about it.
     
    patrick24601, Aug 27, 2010 IP
  8. Jalpari

    Jalpari Notable Member

    Messages:
    5,640
    Likes Received:
    137
    Best Answers:
    0
    Trophy Points:
    260
    #8
    This code not works for my blog.

    yeah i know.
     
    Jalpari, Aug 27, 2010 IP
  9. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #9
    even using the disable of right click it wouldnt matter since you can still view the source from the eidt / view in your browsers top panel.

    as well even plugin's to view the source like firebug and many other tools.


    the better question would be to ask why do you want to disable the right click? to what advantage or reason do you want to disable it?

    Then a possible solution can be made to circumvent that.
     
    lowridertj, Aug 27, 2010 IP
  10. squeenix

    squeenix Peon

    Messages:
    57
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Disabling would be annoying and turn away many potential customers, also Control-U, and Control-C would still work.
     
    squeenix, Aug 28, 2010 IP
  11. .TIEU

    .TIEU Peon

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Disabling right click helps stop non tech savy users from saving images etc. Not everyone can read HTML and parse the code for information.
    The user isn't asking for opinion he is asking how it is done.

    You can't use PHP code to stop right clicking it is a client sided thing as someone already stated. But you can use PHP code to output the client sided code.

    eg:
    
    echo '  <script>
     var isNS = (navigator.appName == "Netscape") ? 1 : 0;
      if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
      function mischandler(){
       return false;
     }
      function mousehandler(e){
         var myevent = (isNS) ? e : event;
         var eventbutton = (isNS) ? myevent.which : myevent.button;
        if((eventbutton==2)||(eventbutton==3)) return false;
     }
     document.oncontextmenu = mischandler;
     document.onmousedown = mousehandler;
     document.onmouseup = mousehandler;
      </script>';
    
    PHP:
     
    .TIEU, Aug 28, 2010 IP
  12. sabato

    sabato Member

    Messages:
    407
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    43
    #12
    human stupidity has no limit. Just cos you disable right click i still can save the whole site on my computer using ctrl + s. Whats the point disable it? If you dont want your visitors save you pictures then dont publish your website. Just keep it on localhost for yourself. There is no way to hide those things that visible in browser. Dont waste your time.
     
    sabato, Aug 28, 2010 IP
  13. Cyb3rgh0st_

    Cyb3rgh0st_ Greenhorn

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #13
    So i was correct about javascript but its no good lol ..
    my badd.
     
    Cyb3rgh0st_, Sep 3, 2010 IP
  14. dakshhmehta

    dakshhmehta Active Member

    Messages:
    220
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    85
    #14
    Hm..i think there are no way to Hide the content of webpages from visitor. The only way to secure your image/content is use image , that is you can use Flash image so that he/she can save but can't edit your image. SO, i think most of you are secure..
     
    dakshhmehta, Sep 4, 2010 IP
  15. upendrau

    upendrau Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    you can use the following script to your document

    <script language=JavaScript>
    var message="Right click disabled!";
    function clickIE4(){
    if (event.button==2){
    alert(message);
    return false;
    }
    }

    function clickNS4(e){
    if (document.layers||document.getElementById&&!document.all){
    if (e.which==2||e.which==3){
    alert(message);
    return false;
    }
    }
    }

    if (document.layers){
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS4;
    }
    else if (document.all&&!document.getElementById){
    document.onmousedown=clickIE4;
    }

    document.oncontextmenu=new Function("alert(message);return false")

    </script>
     
    upendrau, Sep 4, 2010 IP
  16. Jalpari

    Jalpari Notable Member

    Messages:
    5,640
    Likes Received:
    137
    Best Answers:
    0
    Trophy Points:
    260
    #16
    I want something similar to this site when you copy even a single word it leave backlink to that page.
     
    Jalpari, Sep 17, 2010 IP