Obfuscating string values in PHP source code

旧街凉风 提交于 2019-12-02 06:29:46

This is a, frankly, stupid way of "protecting" your code. Hopefully you realize that once the code is delivered to the clients, they can simply undo all of this and extract the values themselves?

Use legal means to protect the code. "here's my code, you are not allowed to share it. If you do, I get $50 kazillion dollars and the Droit de Seigneur with your most beautiful daughter, or an extra 200 kazillion in lieue if they're all ugly".

An iron-clad licensing agreement will be far better protection than any cereal-box decoder-ring wet kleenex method you care to apply ever will be.

sarnold

For further suggestions why this is a waste of your time:

Asked at 8:36, decoded at 8:44. Eight minutes of protection: https://stackoverflow.com/questions/5456462/what-does-this-php-code-do

Asked at 11:01, decoded at 11:17, and very-well analyzed at 11:47. Hacked, what does this piece of code do?

In the first case, I'm willing to bet the majority of the fastest poster's time was spent writing. So feel confident that however you try to obfuscate your code, it'll take only three or four minutes to undo whatever it is you've done.

How much time are you willing to put into obfuscating your code when it'll take someone only a few minutes to undo what you've done? Could that time have been better spent writing awesome features that your customers would love?

ord will get you a character's ASCII value, using that we can generate the 3 things you want.

Type 1: Use dechex to convert int to hex.

$chr = 's';
$hex = dechex(ord($chr)); // 73

Type 2: Use decoct to convert into to octal.

$chr = 'E';
$oct = decoct(ord($chr)); // 105

Type 3: Use the << (shift left) operator.

$chr = 'e';
$bin = ord($chr)<<23; // 847249408
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!