I made a wordpress paid plugin and i am selling. So, to protect my PHP code i am looking for a way to obfuscate my PHP code. I am not going for ionCube because it out of my budget and my client have to install ionCube to run my code which is another annoy.
PHP code for obfuscation :
<?php
function obfuscate($phpCode) {
$obfuscatedCode = '';
for ($i = 0; $i < strlen($phpCode); $i++) {
$obfuscatedCode .= '\\x' . sprintf('%02x', ord($phpCode[$i]));
}
return $obfuscatedCode;
}
$originalCode = '<?php echo "Hello, world!"; ?>';
$obfuscatedCode = obfuscate($originalCode);
echo $obfuscatedCode;
?>
PHP code to evaluate and produce output :
<?php
function decodeObfuscatedCode($obfuscatedCode) {
$decodedCode = '';
for ($i = 0; $i < strlen($obfuscatedCode); $i += 4) {
$hex = substr($obfuscatedCode, $i, 4);
$decodedCode .= chr(hexdec(substr($hex, 2, 2))) . chr(hexdec(substr($hex, 0, 2)));
}
return $decodedCode;
}
$obfuscatedCode = '\x3c\x3f\x70\x68\x70\x0a\x65\x63\x68\x6f\x20\x22\x48\x65\x6c\x6c\x6f\x2c\x20\x77\x6f\x72\x6c\x64\x21\x22\x3b\x0a\x3f\x3e';
$decodedCode = decodeObfuscatedCode($obfuscatedCode);
eval("?>" . $decodedCode);
?>
expected Output :
Hello, world!
Output i am getting :
<?php echo "Hello, world!"; ?>
Problem is my PHP code are printed as string instead of script.