0

I need to stop others from editing or viewing my code for a PHP based project.

I wanted to to "encrypt" (is that the right word?) my PHP code so others can't read it.

Can PHP even do this? My preference if for an open-source/free solution.

Sankar Subburaj
  • 4,992
  • 12
  • 48
  • 79
  • You don't want to encrypt your php file. You want to obfuscate it. If you encrypt it, then it won't work any more. – Roman Dec 20 '11 at 04:51
  • http://stackoverflow.com/questions/232736/code-obfuscator-for-php/232767#232767 – Sankar Subburaj Dec 20 '11 at 05:58
  • 1
    @Snakar, it's true that Obfuscation is not the same. The point I was making is that there is no way to encrypt php files and expect them to work. – Roman Dec 20 '11 at 06:07

3 Answers3

2

You can try PHP bytecode Compiler.

Timofey Stolbov
  • 4,501
  • 3
  • 40
  • 45
2

I guess encode and obfuscate is what you're looking for, e.g. something like:

Jürgen Thelen
  • 12,745
  • 7
  • 52
  • 71
-3

Let's start with the actual PHP function:

function XOREncryption($InputString, $KeyPhrase){
   $KeyPhraseLength = strlen($KeyPhrase);
   // Loop trough input string
   for ($i = 0; $i //SALT
$salt = 'my_special_phrase';

//ENCRYPT
$crypted = base64_encode(XOREncryption('my string', $salt));
echo "Encrypted: " . $crypted . "
";

The variable ' $salt ' plays a crucial role here. It is essentially the 'key' to your encrypted string. The salt value will always generate the same values when the same mathematics are applied to it. It provides the constant needed to generate randomness. This goes to say that if someone uses the salt that was used to generate the encryption and applies the same mathematics they can undo or reverse the encrypted string back into the original string text.

Adam Lear
  • 38,111
  • 12
  • 81
  • 101
  • 1
    1. Your code is broken/incomplete. 2. Do NOT add links to your services or products into your answers. Those links will be removed and your account may be removed as well if you persist. – Adam Lear Dec 20 '11 at 05:03