Information Protection when inspecting the code through the browser

9

I wonder if there is any way to hide the visible code in the inspect / ctrl + U or make it difficult. From what I've been researching PHP makes it difficult to consult the code, do you? What methods do you know about this?

    
asked by anonymous 01.12.2016 / 03:10

1 answer

21

PHP does not make it difficult to copy anything from the front end, you have to understand some things first:

  • front-end

    The front end is a relative term, but in practice it is usually used to refer to what will be rendered in the browser

  • back-end

    The back-end is also relative, but in practice it is generally used to refer to general server-side technologies such as database, HTTP processing program (like Apache and IIS), and dynamic language and frameworks

  • HTTP request

    This is what the browser sends to a server, it occurs when you type a URL in the navigation bar, when you upload a

  • HTTP Response

    The HTTP response is generated after an HTTP request and it will respond according to the request of this request

PHP is a language that can be used (and is usually used) for web pages, it runs on the side that we call the back end, the browser communicates with the server through the HTTP protocol making a request, then PHP processes a script and generates a response, this all occurs on the server and not on the user's machine, every line or entire generated content will be sent as an "HTTP response" to the browser you requested, for example:

Inotherwords,PHPdoesnotrunnexttoHTML,itgeneratesaresponsethatcanbeaHTML"document", such as a TXT, an image, a video, will depend on what you set PHP to send response .

There are many other languages that run on the server and can work with HTTP to generate responses for HTTP requests, such as PHP, Python (usually using a framework), C # (usually using asp.net and asp.net- mvc), Ruby (RubyOnRails framework) and etc are used to make the development of pages more dynamic, for example when accessing a facebook profile in fact all profiles are the "same page", but the data of each profile are populated according to the requisition and the backend generates a version based on the desired content.

Summarizing

In short, you can not protect generated or created HTML, as this is a download process, you can avoid some copy attempts, but anyone who really wants to copy a page will be able to do this for more attempts to prevent it This is because an HTTP response is sent as a download and processed in the browser window, ie it has already been downloaded to the machine.

What you have to worry about is protecting sensitive data, such as passwords, customer data (assuming you have a database), and preventing them from appearing at inappropriate times.

Techniques to try to protect

There are still things you can do to try to protect, of course as I said sensitive data should not be sent as an answer, only if necessary, but if the data is not sensitive and you still want to protect it.

  • You can block the right mouse button with javascript:

    <script>
    if (document.addEventListener) {
        document.addEventListener("contextmenu", function(e) {
            e.preventDefault();
            return false;
        });
    } else { //Versões antigas do IE
        document.attachEvent("oncontextmenu", function(e) {
            e = e || window.event;
            e.returnValue = false;
            return false;
        });
    }
    </script>
    
  • You can also block text selection with CSS:

    <style>
    /*desabilita a seleção no body*/
    body {
        -webkit-touch-callout: none; /* iOS Safari */
          -webkit-user-select: none; /* Chrome/Safari/Opera */
           -khtml-user-select: none; /* Konqueror */
             -moz-user-select: none; /* Firefox */
              -ms-user-select: none; /* Internet Explorer/Edge */
                  user-select: none;
    }
    
    /*habilita a seleção nos campos editaveis*/
    input, textarea {
        -webkit-touch-callout: initial; /* iOS Safari */
          -webkit-user-select: text; /* Chrome/Safari/Opera */
           -khtml-user-select: text; /* Konqueror */
             -moz-user-select: text; /* Firefox */
              -ms-user-select: text; /* Internet Explorer/Edge */
                  user-select: text;
    }
    
    /*habilita a seleção nos campos com o atributo contenteditable*/
    [contenteditable=true] {
        -webkit-touch-callout: initial; /* iOS Safari */
          -webkit-user-select: all; /* Chrome/Safari/Opera */
           -khtml-user-select: all; /* Konqueror */
             -moz-user-select: all; /* Firefox */
              -ms-user-select: all; /* Internet Explorer/Edge */
                  user-select: all;
    }
    </style>
    
  •   

    Important note: It is not possible to block in some browsers and / or situations, because there are keystrokes that are reserved, this varies from browser to browser

    <script>
    if (document.addEventListener) {
        document.addEventListener("keydown", bloquearSource);
    } else { //Versões antigas do IE
        document.attachEvent("onkeydown", bloquearSource);
    }
    
    function bloquearSource(e) {
        e = e || window.event;
    
        var code = e.which || e.keyCode;
    
        if (
            e.ctrlKey &&
            (code == 83 || code == 85) //83 = S, 85 = U
        ) {
            if (e.preventDefault) {
                e.preventDefault();
            } else {
                e.returnValue = false;
            }
    
            return false;
        }
    }
    </script>
    

Other related posts

Again I say, this does not guarantee anything, it only helps a bit, but whoever is deciding to copy your page will do it if you wish, however the work that is making copies of pages people will probably prefer to get "frameworks "like and download layouts or purchase them ready.

About plagiarism

Still if you want to look for other means of protection maybe just the legal means, I do not think that here on the site you will find useful information for this however from a look at the tag #

    

01.12.2016 / 04:16