Re: Will hex code work with PHP?
| From: | Lars Torben Wilson | Date: | Wed, 06 Dec 2000 10:01:23 +0000 |
| Subject: | Re: Will hex code work with PHP? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28809@lists.php.net to get a copy of this message | ||
Dallas Kropka writes:
> I don't know the commercial, but this is what I want to do, I want to hide a
> section of code from others that view it,.... disguised it, and turn it into
> HEX code. It all has to be in the same file, but I don't want others who
> view it to see it.
>
> But if I do this, will PHP know what the code is?
Not directly, no. You'd get 'unexpected character in input'
errors. However, you could do it with eval():
<?php
error_reporting(E_ALL);
$code =
"\x65\x63\x68\x6f\x20\x22\x49\x6e\x20\x65\x6e\x63\x6f\x64\x65\x64" .
"\x20\x63\x6f\x64\x65\x3c\x62\x72\x3e\x5c\x6e\x22\x3b\x0a\x69\x66" .
"\x20\x28\x24\x66\x6f\x6f\x20\x3d\x3d\x20\x27\x62\x61\x72\x27\x29" .
"\x20\x7b\x0a\x20\x20\x20\x65\x63\x68\x6f\x20\x22\x44\x6f\x69\x6e" .
"\x67\x20\x66\x6f\x6f\x3c\x62\x72\x3e\x5c\x6e\x22\x3b\x0a\x7d\x0a";
echo "Doing regular stuff...<br>\n";
$foo = false;
eval($code);
$foo = 'bar';
eval($code);
?>
Here's one way to generate $code:
<?php
error_reporting(E_ALL);
$codestr = '
echo "In encoded code<br>\n";
if ($foo == "bar") {
echo "Doing foo<br>\n";
}
22';
$code = '';
$len = strlen($codestr);
for ($i = 0; $i < $len; $i++) {
$code .= '\x' . dechex(ord($codestr[$i]));
}
echo $code;
?>
Anyway, this will not help you much, since the slightest examination
of the above would reveal the actual code: all you'd need to do would
be to put an 'echo $code;' right before the eval(), and your hidden
code is shown. Which would also be the case if you *could* code the
hex directly into the source file: you could just copy-n-paste it into
another file, assign it to a string, and echo it.
So I guess I'm saying that no, you cannot do what you want in
PHP. The forthcoming encoder should handle stuff like this, IIRC, but
I believe you'll need to encode whole files with it, and not just
sections.
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+