Reputation: 1705
I don't want to give my code to client. I know there is no any such way which make my code 100% secure from client or editing by other developers but at least i think from may clients i can hide my code, for this i am using the following way:
For example, I have the following code:
$php = base64_encode('<?php function add($a,$b){echo($a+$b);} add(30,40); ?>');
The above line produces the following code of my php code:
PD9waHAgZnVuY3Rpb24gYWRkKCRhLCRiKXtlY2hvKCRhKyRiKTt9IGFkZCgzMCw0MCk7ID8+
I used gzencode() method to compress the above generated code like this:
$txt = "PD9waHAgZnVuY3Rpb24gYWRkKCRhLCRiKXtlY2hvKCRhKyRiKTt9IGFkZCgzMCw0MCk7ID8+";
$ph = gzencode($txt,8);
I can get the Original php code by using the following code:
echo(base64_decode($ph));
It produces:
<?php function add($a,$b){echo($a+$b);} add(30,40); ?>
Now, this code shows in the source code in the browser but i want to run this code like the original php code, so, what i have to do to make this executable?
Thanks
Upvotes: 2
Views: 79
Reputation: 4397
You can use eval to run the string as inline code. Check this (eval) You can also create an anonymous function which your string code should be inside (create_function)
Upvotes: 2