PHP code Protection Details of the use of Zend Guard

  • 2020-06-03 06:03:38
  • OfStack

The purpose of Zend Guard is to protect the PHP source code from decomcompiled views, unauthorized custom modifications, unauthorized use, redistribution, etc. What's more, it was developed by Zend, the company that owns PHP, as a completely customized guardian for PHP.
Below, please learn to use Zend Guard with me 1, encryption protection of our PHP source code.

Combat: Encryption PHP source code
Download: http: / / www. zend. com/en/products guard /
Next, let's prepare a simple PHP program, test.php, to test whether it can be protected by Zend Guard. The code for ES27en. php is as follows:


Open Zend Guard, click from the File (File) menu, and create a new project, as shown in Figure 1. Click Next to enter the interface of directory and file addition. Since we are only testing one file, click Add File to add test.php and then click Finish (complete) to generate the project.

At this point, Zend Guard automatically opens the newly created project, listing the files in the project on the left side of the interface, and listing the relevant information of the project on the right side. We are now ready to compile the source code. Click Encode (compile) in Links (link) on the right, and the Console (console) window at the bottom of the screen shows "The operation has successfully." meaning the compilation is complete.
Now if you go to the directory where the encrypted file was saved, you will see that there is also one ES54en.php. Is it the same as the original ES56en.php1? Open it with editing software, and you can see that it is no longer the same, as shown in Figure 2. Note: self 1 must save the original code, otherwise lost, even you can not view and modify.

Next, test the encrypted code under 1, access the encrypted PHP program from the browser, oops, error, cannot run, and display the information as shown in Figure 3. Originally, using Zend Guard encryption PHP program, but also need a partner - Zend Optimizer, in order to normal execution and improve efficiency. From http: / / www. zend. com en/products/guard/download and install. During installation, step 1 of "Choose the php ini folder" indicates the location of the configuration file of PHP on the system, and step 1 of "Choose the Web server root folder folder" indicates the location of the Web server software. Once the installation is complete, open php.ini with Notepad, and at the end we will see configuration information similar to the following:
zend_extension_manager.optimizer_ts="E:\Program Files\Zend\ZendOptimizer-3.3.0\lib\Optimizer-3.3.0"
zend_extension_ts="E:\Program Files\Zend\ZendOptimizer-3.3.0\lib\ZendExtensionManager.dll"
This means that Zend Optimizer has been installed successfully. We can restart the Web server software and let Zend Optimizer take effect. Note: If the server you are using is already installed or contains Zend Optimizer, you do not need to install it again.
Now again from the browser to access the encrypted PHP program to try, as expected it can run normally, from the displayed information, we can see the information of Zend Optimizer
Analysis of Zend Guard encryption principle
Let's take a look at the process to get an idea of how Zend Guard works. The PHP source code is compiled to encrypted code with Zend Guard and then executed with PHP loaded with Zend Optimizer. Distribution to others, is the encrypted code, can be executed, but no source code, others can not see and modify. Therefore, we can add the appropriate code in the program to detect the current time of the system, see whether the preset deadline has been exceeded, and if so, exit the program to stop execution.

Zend Guard works in a similar way to Java. The compiled PHP program is just like the compiled Java2 base code, which needs support from JVM to run. Zend Optimizer can be regarded as the VIRTUAL machine of PHP. Zend Guard and Zend Optimizer work together to compile, encrypt, and execute the compiled code.

The License management aspect is a deeper use that can be used to generate license files to limit application usage by selecting different license modes, such as concurrent users, time limits, network segments, or specific servers. Interested readers can check out Zend Guard's own help file for specific usage.

Related articles: