• 12
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

How to prevent users from copying content from website

Is there any way to prevent users from copying content from website and display encrypted code in view source?

I know that techies will always find a way but if it prevents normal users it's OK.

Check out ionCube HTML Obfuscator:-

http://www.ioncube.com/html_encoder.php

As of the text contents, Try this code:- Live Demo (IE isn't supported)

<script type="text/javascript">
document.oncopy = function(){
    var bodyEl = document.body;
    var selection = window.getSelection();
    selection.selectAllChildren( document.createElement( 'div' ) );
};
</script>
  • 5
Reply Report
      • 2
    • The ionCube obfuscator is a really bad, outdated solution (notice the 2003 copyright on their code). Yes, view->source will obfuscate the code, but Developer tools in Chrome will output the POST-javascript DOM, meaning you can see the code plain as day. By using that all you're doing is forcing users to have javascript enabled, but it really provides no extra security.
      • 1
    • Hello Jeff, did you read the question? ".... and display encrypted code in view source? I know that techies will always find a way but if it prevents normal users it's OK."
    • since when do non-techies view the source code anyway? is the objective to hide the source code from people who can write html/javascript but don't know how to hit ctrl+I in chrome? clicking 'view source' is no less technical than clicking 'developer tools'
    • We are trying to hide the text contents not the source code ( don't make me quote the question again ). And well when the above JavaScript wont let them copy the text then most of them will try to get it from the source code ( via "View Source"). Anyway, you should ask about this to the question asker.

Given the tags you used:

  • PHP is server-side code, and your end-users will never see your code
  • HTML cannot be hidden from end-users
  • Javascript and jQuery cannot be hidden either, but they can be obfuscated by 'minifying' the code. Typically this is done using a program like JSmin (online tool available at http://jscompress.com/)
  • 4
Reply Report
      • 2
    • Text content: no. Images: no, but you can stop users from right clicking an image (to save) or hide your image in a canvas tag (these are very easy to circumvent). Music/movies: No, but some formats make this trickier, such as extracting an mp3 out of Youtube. Pretty easy to circumvent, though. Please be more specific as to what type of content, and perhaps we can help a bit more, but the short answer is that for most content, there is nothing you can do that can't be circumvented quite easily.

No, there is not. The user will always be able to access the data sent to the browser. Encryption doesn't help here, because the data has to be decrypted at some point in order to be displayed on the screen.

  • 2
Reply Report

For a laic user you can block right click event, ctrl+c, ctrl+insert key events on window. But for a more advanced user, there is no way you can block the content from being copied if you are using HTML. Flash would solve it, but who still uses flash for content, right?

  • 1
Reply Report

You can use these tags ..

//$("body").css("-webkit-user-select", "none");
//$("body").css("-moz-user-select", "none");
//$("body").css("-ms-user-select", "none");
//$("body").css("-o-user-select", "none");
//$("body").css("user-select", "none");
  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions