note 15532 added to function.bin2hex
| From: | mail at philipp-louis dot de | Date: | Sun, 16 Sep 2001 01:12:10 +0000 |
| Subject: | note 15532 added to function.bin2hex | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-18052@lists.php.net to get a copy of this message | ||
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.
http://www.php.net/manual/en/function.bin2hex.php