Disable Control dan Right Click di PHP

Disable Control dan Right Click di PHP

P ernah membuat ujian online atau aplikasi lainnya yang menggunakan PHP atau malah ingin script kita tidak di copy oleh orang lain dengan men-disable control dan klik kanan.

ada beberapa script JQuery untuk itu semua, diantaranya yang akan saya bagikan ini:

men-disable klik kanan pada browser

<br />
&lt;body oncontextmenu=&quot;return false;&quot;&gt;<br />
     &lt;!-- apabila return false diganti dengan true maka akan meng-enable klik kanan --&gt;</p>
<p>     &lt;-- script disini --&gt;<br />
&lt;/body&gt;<br />

 

men-disable F5 dan Ctrl+R (Reload), taruh script dibawah ini diantara tag head

<br />
&lt;script type=&quot;text/javascript&quot;&gt;<br />
	document.onkeydown = function() {<br />
		switch (event.keyCode) {<br />
			case 116 : //F5 button<br />
				event.returnValue = false;<br />
				event.keyCode = 0;<br />
				return false;<br />
			case 82 : //R button<br />
				if (event.ctrlKey) {<br />
					event.returnValue = false;<br />
					event.keyCode = 0;<br />
					return false;<br />
				}<br />
		}<br />
	}<br />
&lt;/script&gt;<br />

 

men-disable Ctrl+U supaya tidak bisa melihat script dan mengarahkan ke link yang kita inginkan, taruh script dibawah ini diantara tag head

<br />
&lt;script type='text/javascript'&gt;<br />
	//&lt;![CDATA[<br />
	shortcut={<br />
		all_shortcuts:{},<br />
		add:function(a,b,c){<br />
			var d={<br />
				type:&quot;keydown&quot;,propagate:!1,disable_in_input:!1,target:document,keycode:!1<br />
			};<br />
			if(c)for(var e in d)&quot;undefined&quot;==typeof c[e]&amp;&amp;(c[e]=d[e]);else c=d;d=c.target,&quot;string&quot;==typeof c.target&amp;&amp;(d=document.getElementById(c.target)),a=a.toLowerCase(),e=function(d){<br />
				d=d||window.event;if(c.disable_in_input){<br />
					var e;d.target?e=d.target:d.srcElement&amp;&amp;(e=d.srcElement),3==e.nodeType&amp;&amp;(e=e.parentNode);if(&quot;INPUT&quot;==e.tagName||&quot;TEXTAREA&quot;==e.tagName)return<br />
				}<br />
				d.keyCode?code=d.keyCode:d.which&amp;&amp;(code=d.which),e=String.fromCharCode(code).toLowerCase(),188==code&amp;&amp;(e=&quot;,&quot;),190==code&amp;&amp;(e=&quot;.&quot;);var f=a.split(&quot;+&quot;),g=0,h={<br />
					&quot;`&quot;:&quot;~&quot;,1:&quot;!&quot;,2:&quot;@&quot;,3:&quot;#&quot;,4:&quot;$&quot;,5:&quot;%&quot;,6:&quot;^&quot;,7:&quot;&amp;&quot;,8:&quot;*&quot;,9:&quot;(&quot;,0:&quot;)&quot;,&quot;-&quot;:&quot;_&quot;,&quot;=&quot;:&quot;+&quot;,&quot;;&quot;:&quot;:&quot;,&quot;'&quot;:'&quot;',&quot;,&quot;:&quot;&lt;&quot;,&quot;.&quot;:&quot;&gt;&quot;,&quot;/&quot;:&quot;?&quot;,&quot;\\&quot;:&quot;|&quot;<br />
				},<br />
				i={<br />
					esc:27,escape:27,tab:9,space:32,&quot;return&quot;:13,enter:13,backspace:8,scrolllock:145,scroll_lock:145,scroll:145,capslock:20,caps_lock:20,caps:20,numlock:144,num_lock:144,num:144,pause:19,&quot;break&quot;:19,insert:45,home:36,&quot;delete&quot;:46,end:35,pageup:33,page_up:33,pu:33,pagedown:34,page_down:34,pd:34,left:37,up:38,right:39,down:40,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123},j=!1,l=!1,m=!1,n=!1,o=!1,p=!1,q=!1,r=!1;d.ctrlKey&amp;&amp;(n=!0),d.shiftKey&amp;&amp;(l=!0),d.altKey&amp;&amp;(p=!0),d.metaKey&amp;&amp;(r=!0);for(var s=0;k=f[s],s&lt;f.length;s++)&quot;ctrl&quot;==k||&quot;control&quot;==k?(g++,m=!0):&quot;shift&quot;==k?(g++,j=!0):&quot;alt&quot;==k?(g++,o=!0):&quot;meta&quot;==k?(g++,q=!0):1&lt;k.length?i[k]==code&amp;&amp;g++:c.keycode?c.keycode==code&amp;&amp;g++:e==k?g++:h[e]&amp;&amp;d.shiftKey&amp;&amp;(e=h[e],e==k&amp;&amp;g++);if(g==f.length&amp;&amp;n==m&amp;&amp;l==j&amp;&amp;p==o&amp;&amp;r==q&amp;&amp;(b(d),!c.propagate))return d.cancelBubble=!0,d.returnValue=!1,d.stopPropagation&amp;&amp;(d.stopPropagation(),d.preventDefault()),!1},this.all_shortcuts[a]={callback:e,target:d,event:c.type},d.addEventListener?d.addEventListener(c.type,e,!1):d.attachEvent?d.attachEvent(&quot;on&quot;+c.type,e):d[&quot;on&quot;+c.type]=e},remove:function(a){var a=a.toLowerCase(),b=this.all_shortcuts[a];delete this.all_shortcuts[a];if(b){var a=b.event,c=b.target,b=b.callback;c.detachEvent?c.detachEvent(&quot;on&quot;+a,b):c.removeEventListener?c.removeEventListener(a,b,!1):c[&quot;on&quot;+a]=!1}}},shortcut.add(&quot;Ctrl+U&quot;,function(){ top.location.href=&quot;https://andihartono.net/kamu-ketahuan/&quot; }); //]]&gt;<br />
&lt;/script&gt;<br />

URL pada top.location.href=”https://andihartono.net/kamu-ketahuan/” bisa diganti dengan URL yang diinginkan.

Demo
Share