Thread: Encrypt output HTML | snippet (PHP)

Results 1 to 6 of 6
  1. #1 Encrypt output HTML | snippet (PHP) 
    Registered Member MDev's Avatar
    Join Date
    Apr 2015
    Age
    24
    Posts
    110
    Thanks given
    21
    Thanks received
    11
    Rep Power
    6
    Hello Rune-Server users,

    Bin working on a project and my custumor asked if there was a way to display the generated view in a js code string like smartgb.com offers with their free HTML Encrypter, and i said yes of course there is.
    Even though i told him that people who realy wanted to copycat the content could easily do it.

    Demo: view-source:[Only registered and activated users can see links. ] make sure to view page source (and not the developer console) to see it's encrypted content | I have only enabled this function on that page for preview purposes.
    Uncrypted version: view-source:[Only registered and activated users can see links. ]
    And for us web developers we do know once the page is fully loaded and the JS is executed we will have a readable HTML/CSS mockup in any developer console.

    Here's my function to encrypt your output HTML:

    Code:
    <?PHP
    function encryptHtml($content) //Post request naar smartgb.com met nodige velden
    {
        if(checkdnsrr('http://www.smartgb.com', 'ANY'))
        {
            $url = 'http://www.smartgb.com/free_encrypthtml.php?do=crypt';
            
            $fields = array(
                    'h'=>$content,
                    's'=>"extended",
                    'Skicka'=>"Encrypt HTML"
            );
            
            $postvars='';
            $sep='';
            foreach($fields as $key=>$value)
            {
                $postvars.= $sep.urlencode($key).'='.urlencode($value);
                $sep='&';
            }
            
            $ch = curl_init();
            
            curl_setopt($ch,CURLOPT_URL,$url);
            curl_setopt($ch,CURLOPT_POST,count($fields));
            curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
            curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
            
            $result = curl_exec($ch);
            
            curl_close($ch);
            
            
            error_reporting(0);
            $doc = new DOMDocument();
            $doc->loadHTML($result);
            $els = $doc->getElementsByTagName('textarea');
            for($i = $els->length; --$i >= 0; )
            {
              $el = $els->item($i);
              if($el->getAttribute('name') == 'Textruta')
              {
                  $encryption = $el->nodeValue;
              }
            }
            $doc->saveHTML();
            if(isset($encryption))
            {
                return $encryption;
            }
            else
            {
                return "Please check out the site smartgb, unable to retrieve the encryption. External page probably changed or moved content.";
            }
        }
        else
        {
            //Server offline return standard HTML
            return $content;
        }
    }
    The above code actualy sends a POST request to their site and retrieves the response, than it loops through the dom document to find the textarea with name: Textruta once found it saves the field value inside a variable that get's printed out at the end of the function.

    If you want this to work without overload you have to make sure all view content is in one variable (as you don't want to make multiple POST requests to their server).
    In my application for example i output all of my html with one var:

    Code:
    echo $twig->render('/src/Views/admin/cms.twig',$twigVars);
    Now when you have included the above function somewhere accessible by your whole app you can easily change the above echo line into:
    Code:
    echo encryptHtml($twig->render('/src/Views/admin/cms.twig',$twigVars));

    When done corectly and you view your website's source you would see a html mockup and a large script tag with unreadable code.
    Perfect for people who want to stop a few copycat's just not all of them.

    Code not woking? Please check your server's PHP version and update to the most recent stable version.
    Still having problems? Please ask.



    Thanks for reading
    MiCa
    Back for a while
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Mar 2013
    Posts
    318
    Thanks given
    86
    Thanks received
    56
    Rep Power
    0
    login page doesnt really match your background, try to add some opacity using RGBA
    [Only registered and activated users can see links. ]
    Need a reliable programmer for your website?
    Add me on skype and let's talk!
    (Cheap and active, 24/7 support)
    Reply With Quote  
     

  3. #3  
    Registered Member wtf its me's Avatar
    Join Date
    Jul 2015
    Posts
    38
    Thanks given
    7
    Thanks received
    4
    Rep Power
    0
    Nice one, I hope to see more and more tutorials man.
    ]
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Nov 2013
    Posts
    180
    Thanks given
    46
    Thanks received
    37
    Rep Power
    0
    why would you want to "encrypt" html (its not encrypting) anyway. is it to prevent them to view source? well...
    Reply With Quote  
     

  5. #5  
    Registered Member MDev's Avatar
    Join Date
    Apr 2015
    Age
    24
    Posts
    110
    Thanks given
    21
    Thanks received
    11
    Rep Power
    6
    Yes, this will prevent many starters from copying your website, however as i've told before once the website is loaded on your screen and you open up a dev console all elements and code will be visible. Because once that "converted" js is loaded it will print out your elements and other code like js, css,...
    To me it's still encrypting because we've made it possible to hide our whole view source into a long and unreadable JS string, most likley advanced developers will always be able to copycat you because of their knowledge however do they realy need to copy you when having all that knowledge ?
    Back for a while
    Reply With Quote  
     

  6. #6  
    Registered Member
    Sieu's Avatar
    Join Date
    Dec 2011
    Age
    24
    Posts
    1,167
    Thanks given
    186
    Thanks received
    131
    Rep Power
    160
    >inspect element

    >clicks on <html>

    >copy

    if someone wants to copy your content, take that as a compliment, for the most part... 95% of the time most content isn't worth stealing.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Webclient HTML snippet
    By krisnka in forum Snippets
    Replies: 5
    Last Post: 07-13-2012, 08:40 PM
  2. HTML XHTML php java
    By pk flavor in forum Help
    Replies: 3
    Last Post: 07-15-2011, 01:16 AM
  3. Replies: 6
    Last Post: 01-25-2011, 05:39 AM
  4. Replies: 8
    Last Post: 12-29-2010, 04:08 PM
  5. Mega Collection of Cheat Sheets with HTML, CSS, PHP, Javascript
    By JavaScriptBank in forum Website Development
    Replies: 0
    Last Post: 09-27-2010, 03:00 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •