note 15532 deleted from function.bin2hex by didou
| From: | didou@php.net | Date: | Sun, 18 May 2003 01:02:44 +0000 |
| Subject: | note 15532 deleted from function.bin2hex by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-48309@lists.php.net to get a copy of this message | ||
Note Submitter: mail@philipp-louis.de
----
If for some reason you want to prevent your HTML output (e.g. JavaScripts) from being stolen by
simple code thiefs or parsed by dumb bots, it might be a good idea to encrypt it using this
technique:
<?php
$output = "<P>Blah blah blubb.</P>";
$output .= "<P>Blubb blubb blah.</P>";
/*
Use something like this to store the output in a string instead of echo-ing it directly to the
browser.
*/
for($count = 0; $count < strlen($output); $count++)
{
$escaped .= "%" . bin2hex($output[$count]);
}
$code = "<HTML><HEAD><SCRIPT
LANGUAGE=\"javascript\">\n<!--\ndocument.write(unescape(\"$escaped\"));\n//-->\n</SCRIPT></HEAD></HTML>";
echo $code;
?>
Anyone using the browser's "view source" function will see the following:
<HTML><HEAD><SCRIPT LANGUAGE="javascript">
<!--
document.write(unescape("%3c%50%3e%42%6c%61%68%20%62%6c%61%68%20%62%6c%75%62%62%2e%3c%2f%50%3e%3c%50%3e%42%6c%75%62%62%20%62%6c%75%62%62%20%62%6c%61%68%2e%3c%2f%50%3e"));
//-->
</SCRIPT></HEAD></HTML>
Of course this won't help against more serious efforts to steal your code, but it will irritate
the spam and copy'n'paste folks.