I think it is impossible because right click is client-side event and not server-side event, and PHP is server-side scripting language.
why would u want to disable right click anyways lol .. and im sure u can get javascript for this . i may be wrong
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.
Oh! good point, i just forget. I tried javascript but that is not the security since it can easily break. well said.
You can successfully disable the right click by using jQuery. $(document).ready(function() { $(document).bind("contextmenu",function(e){ return false; }); }); Code (markup):
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.
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.
Disabling would be annoying and turn away many potential customers, also Control-U, and Control-C would still work.
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:
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.
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..
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>
I want something similar to this site when you copy even a single word it leave backlink to that page.