I would like to prevent users from viewing the source code using browser (view->source). I have seen it disabled on a website, I just can not remember the site.

Can someone please let me know if this is possible with php or some other language?

Thank you all in advance for all your help.

Gil

    your php will not show in the source from the browser (if that is what you are worried about) it is all parsed on the server and then basicilly just html is sent to the browser.

    if you still need to find it, http://www.dynamicdrive.com has a couple of scripts.

      include in <BODY>
      == Cut here ==
      <Script Language="JavaScript">
      //Disable right click script III- By Renigade (renigade@mediaone.net)
      //For full source code, visit http://www.dynamicdrive.com

      var message="";
      ///////////////////////////////////
      function clickIE() {
      if (document.all) {
      (message);
      return false;
      }
      }
      function clickNS(e) {
      if (document.layers||(document.getElementById&&!document.all)) {
      if (e.which==2||e.which==3) {
      (message);
      return false;
      }
      }
      } // # end function
      if (document.layers || navigator.userAgent.indexOf("Opera") >=0){
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown=clickNS;
      }
      else{
      document.onmouseup=clickNS;
      document.oncontextmenu=clickIE;
      }

      document.oncontextmenu=new Function("return false")
      </SCRIPT>

      === end cut ==

      unfortunately, it only disables Right Click, not a Browsers View->Source..

        In the end, if someone really wants to find the source and knows what they are doing, they can get it, because HTML functions by caching the files where a savvy user could open notepad and javascript or no, they have your code.

        However, use acey99's script. After that, you can disable the tool bars at the top of the browser to keep them from using the drop-down menus. At that point, most people won't know how to get it from there.

          FYI, here's a way to view source that will always work:

          Open up the page you want the source of and then, while that window is open, look in your browser's temporary internet files folder for that page. Copy it to a new location and then open it with a text editor - voila.

          Of course, as mrsocks said, php code is not sent to the client at all, so the above method will still only show you the output (html) of php pages.

            Yeah, and the last little remark to be made that manipulating browser abilities (removing menus, blocking r-click) is highly disliked by the most part of visitors. It's notvery good practice, really, and your HTML scarcely worth it.

            And here's one more method for hiding code: you may write some complicated javascript decoding function and send all the content in encoded form as a variable. Then JS decodes it when displaying the page. Then the only way to get the source is to decode content more or less manually, and it can be real pain in the a.
            Besides, this technique can be used to prevent e-mails on your pages from being scanned by spam robots.

              why dont you encrypt your html??? like phpgardian etc... so if they view your source, good luck trying to read it

                Originally posted by the_Igel
                And here's one more method for hiding code: you may write some complicated javascript decoding function and send all the content in encoded form as a variable. Then JS decodes it when displaying the page. Then the only way to get the source is to decode content more or less manually, and it can be real pain in the a.
                Besides, this technique can be used to prevent e-mails on your pages from being scanned by spam robots.

                Yeah, that's a good method to keep spam bots from stealing e-mails. But it's still easy to get the source code from it -- just change the document.write commands in the decryption script to write to a new blank window instead of the current window. Then you can view the source of the new window and see the result.

                There's always an easy way around any client-side web page security. Check out the LoginMatrix HackMe Challenge and test your javascript cracking skills.

                  Just curious, but why bother stopping people from seeing the source? There is no security gained by it.

                  And crippling the browser by turning off Right Click and the Toolbar is a sure way to make people leave and never come back. Check out #10 in this list: http://www.vortex-webdesign.com/help/dontdoit.htm

                    Write a Reply...