How can i encrypt a function or its contents in a php class?
How can i encrypt a function or its contents i开发者_如何学运维n a php class ?
e.g. Take a look at below class, i would like to encrypt the function test1() so the code inside will never be revealed but executes as normal
class test
{
var $x;
var $y;
function test1()
{
return $this->x;
}
function test2()
{
return $this->y;
}
}
Thanks in advance
The code can't really be hidden from someone that has access to the file, but it can be obfuscated. There are too many alternatives, try google 'php obfuscate'.
Keep in mind that even though it will be harder, it will by no means be impossible for a skilled coder to quickly discern what happens in your code (especially if it's as simple as the example you provided).
Extract test1 to base class:
abstract class testBase {
function test1(){
return $this->x;
}
}
Encode it with http://www.zend.com/en/products/guard/. Then use testBase as test parent:
class test extends testBase {
public $x;
public $y;
function test2(){
return $this->y;
}
}
精彩评论