Jump to content

The RuneLocus forum has been archived and does not accept new registrations.
Click here for more information, and click here to join the community on Discord.

Encrypt your output HTML | Stop a few copycats | snippet


MiCaDev
 Share

Recommended Posts

Hello Runelocus 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:[url]http://mafiasource.be/login[/url] 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:[url]http://mafiasource.be/register[/url]
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;
}
}
[/code]

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);
[/code]

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));
[/code]


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
Link to comment
Share on other sites

[quote name='Hope']Yeah, it's really not worth it to encrypt. If someone came along who wanted to, chances are that they're computer proficient enough to do so.[/QUOTE]
To do what, exactly? Copy the website format? I highly doubt they'd have the knowledge to decrypt much of anything. I learned about viewing page sources before I even started web developing.

As for being on topic: Good job on this! Honestly, I'm happy to see the web development section being used more. This is a nice tutorial, and a great read!
Link to comment
Share on other sites

  • 11 months later...

I think encrypting HTML code is not so useful because of no one will want to encrypt their html code. Everyone want to encrypt function code but with HTML why anyone will encrypt their structure?

 

I mean I will encrypt php code because of it contain function while HTML does not contain major function and only use for graphic design.

Link to comment
Share on other sites

  • 1 month later...
On 11-9-2015 at 9:07 PM, Hope said:

Yeah, it's really not worth it to encrypt. If someone came along who wanted to, chances are that they're computer proficient enough to do so.

 

On 13-8-2016 at 3:03 PM, WindowsRSPS said:

I think encrypting HTML code is not so useful because of no one will want to encrypt their html code. Everyone want to encrypt function code but with HTML why anyone will encrypt their structure?

 

I mean I will encrypt php code because of it contain function while HTML does not contain major function and only use for graphic design.

Say that to Google, ever watched their HTML code?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...