Disable copy/paste with php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

Disable copy/paste with php?

Post by lauthiamkok »

Hi,

I wonder if there is any way to disable [cntl + c] and [cntl + v] from an input field to another input field with php?

I can do this easily with jquery below, but what if I turn off javascript on my browser - it won't work for sure...

Code: Select all

<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){ 
    
	$('#message_email').bind('paste', function(e){ 
		alert('Sorry, pasting is not allowed. Please type in.');
		return false;
		});

  });
  </script>

</head>
<body>
  <div><input name="message_email" id="message_email" type="text"/></div>
</body>
</html>
Many thanks,
Lau
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Disable copy/paste with php?

Post by requinix »

No. There is no way. And personally, I hate it when people try to do that.
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Disable copy/paste with php?

Post by omniuni »

lauthiamkok wrote:Hi,

I wonder if there is any way to disable [cntl + c] and [cntl + v] from an input field to another input field with php?

I can do this easily with jquery below, but what if I turn off javascript on my browser - it won't work for sure...

Many thanks,
Lau
You could try binding an alert to "onkeydown" and checking if it is a [ctrl] key, and alerting the user if it is.
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

Re: Disable copy/paste with php?

Post by lauthiamkok »

tasairis wrote:No. There is no way. And personally, I hate it when people try to do that.
the main reason is some people would type the email incorrectly in the first input field which happens to myself sometimes.... lol

the message is sent but cannot reach the sender for verification bcos they type the email address incorrectly...

so if I have been forced to type the email twice then I would pay more attention... :P
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

Re: Disable copy/paste with php?

Post by lauthiamkok »

omniuni wrote:
You could try binding an alert to "onkeydown" and checking if it is a [ctrl] key, and alerting the user if it is.
this requires JavaScript isn't?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Disable copy/paste with php?

Post by requinix »

lauthiamkok wrote:the main reason is some people would type the email incorrectly in the first input field which happens to myself sometimes.... lol

the message is sent but cannot reach the sender for verification bcos they type the email address incorrectly...

so if I have been forced to type the email twice then I would pay more attention... :P
There's only so far you can go to protect people from themselves. I, for one, wish there was less of this going on as it would encourage responsibility.

If they can't bother to check that their email address is correct then it's their fault.
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Disable copy/paste with php?

Post by omniuni »

lauthiamkok wrote:
omniuni wrote:
You could try binding an alert to "onkeydown" and checking if it is a [ctrl] key, and alerting the user if it is.
this requires JavaScript isn't?
Yes, I'm afraid so. You can not disable something in the browser from the server side.
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

Re: Disable copy/paste with php?

Post by lauthiamkok »

omniuni wrote:
Yes, I'm afraid so. You can not disable something in the browser from the server side.
i think it was a bad idea of mine to have that. it's better off doing this thing on server side only. thanks mate :)
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

Re: Disable copy/paste with php?

Post by lauthiamkok »

tasairis wrote:
If they can't bother to check that their email address is correct then it's their fault.
yes it is true! :lol:
Post Reply