[PHP] Encrypting PHP with ZendGuard

Downloading ZendGuard

Official download link: http://www.zend.com/en/products/guard/downloads#Windows

Registration is required before downloading. I downloaded Zend Guard 6.0. Simply double-click to run the installer.

image001

The latest version is 7.0. If you want to download an earlier version, click “>Download here” and a list of older versions will appear below the current page.

image003

Downloading PHP

Official download links: http://php.net/downloads.php | http://php.net/releases/

My current version: http://windows.php.net/download/#php-5.4

PHP typically releases two types of builds for each version: Thread Safe and Non Thread Safe.

Important note: ZendGuard only supports Non Thread Safe builds. So please download the Non Thread Safe version of PHP.

Configuring PHP – ZendLoader.dll

  1. Download ZendLoader.dll

    Official download link: http://www.zend.com/en/products/loader/downloads#Windows

    Registration is required before downloading. Similar to ZendGuard, make sure to select the ZendLoader version that matches your PHP version.

    image005

    Copy ZendLoader.dll to the PHP [PHP root directory]\ext\ folder.

  2. Rename php.ini-development or php.ini-production to php.ini,
    and add the following content to php.ini:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    
    zend_extension="./ext/ZendLoader.dll"
    
    ; Enables loading encoded scripts. The default value is On
    zend_loader.enable=1
    
    ; Disable license checks (for performance reasons)
    zend_loader.disable_licensing=0
    
    ; The Obfuscation level supported by Zend Guard Loader. The levels are detailed in the official Zend Guard Documentation. 0 - no obfuscation is enabled
    zend_loader.obfuscation_level_support=3
    
    ; Path to where licensed Zend products should look for the product license. For more information on how to create a license file, see the Zend Guard User Guide
    zend_loader.license_path=
    

Creating PHP Code

Create an input folder, and inside it create test.php.

Code:

1
2
3
4
5
<?php 
date_default_timezone_set("Asia/shanghai"); 
echo "Thanks ZendGuard!\n"; 
echo "Now datetime is ".date("Y-m-d h:i:s")."\n"; 
?>

The above code outputs:

Thanks ZendGuard

Now datetime is [current time].

Installing ZendGuard and Creating a Project

ZendGuard has a straightforward installer. After installation, launch it and you’ll see:

image007

  1. Create a new Zend Guard Project.
  2. Set the output directory to the output folder.
    image009
  3. Add the input folder as the input directory.
  4. Select the PHP version.
    image011
  5. Click image015
  6. A new test.php is generated in the output folder. Opening it reveals garbled content (the encrypted code).

Running Source Code and Encrypted Code

Running the source code:

image017

Running the encrypted code:

image019

With this, you can now use ZendGuard to encrypt PHP code.