Home arrow PHP arrow Page 3 - PHP Encryption and Decryption Methods

PHP Eval Function in Encoding Methods - PHP

PHP encryption is a method of obfuscating scripts in such a way that it offers additional protection and prevents unauthorized editing of the scripts. This article discusses both encryption and decryption.

  1. PHP Encryption and Decryption Methods
  2. Base 64 Encoding and Compression/Decompression Techniques
  3. PHP Eval Function in Encoding Methods
  4. Case Example: Encoding a Working PHP Script
By: Codex-M
Rating: starstarstarstarstar / 13
November 03, 2009

print this article



Since the encrypted output is a string (after applying compression and base 64 encoding techniques), we need to tell PHP that the encoded string is indeed a script. To do this, we need to use the eval() function in PHP. The purpose of this function is to evaluate a string as a PHP code; you can research the details of the eval() function on your own.

The standard encoded PHP script (encrypted) takes a form similar to this example:

<?php eval(gzinflate(base64_decode('FZfHDoTYEUV/ZXYzIxbkJFseAU1qcg4bi9TknPl64z0SUK/evef8859///
NHcSTdX+VTD78u2Yq/0mQtCOyA7YSRf3y'))); ?>

To encode the PHP script into the above form, we will utilize the steps below:

Step 1: Capture the PHP script to be encoded and convert it to a string, except for the PHP tags (<?php and ?>)

Step 2: Compress the string using the gzdeflate function (using the maximum compression level) and assign the compressed string to a PHP variable.

Step 3: Encode the compressed string using base 64 encoding and assign the encoded string to a PHP variable.

Step 4: To let PHP interpret/parse correctly the encoded scripts, append the decoding, decompression and use eval functions, as shown below:


eval(gzinflate(base64_decode(‘This is the encoded and compressed PHP script strings except the start <?php and end tags ?>’)));


>>> More PHP Articles          >>> More By Codex-M

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: