Zend guard is used to protect PHP source code from decompilation and viewing, custom modification without authorization, and unauthorized use and re-release. In addition, it is developed by PHP's Zend company and is a completely customized protector for PHP.
Next, please join me to learn how to use Zend guard to encrypt and protect our PHP source code.
Practice: encrypt 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 test. php is as follows:
<? PHP
Phpinfo ();
?>
Open Zend guard and click "file" to create a new project, as shown in figure 1. Click Next To go to the directory and file adding interface. Because we only test a file, click Add file to add test. php. Then click Finish to generate the project.
At this time, Zend guard will automatically open the new project, list the files in the project on the left side of the interface, and list the project information on the right side. Now we can compile the source code. Click encode (compile) in the link on the right. The "the operation has completed successfully." is displayed in the console window at the bottom of the interface, indicating that the compilation is completed.
Now, in the directory saved in the encrypted file, we can see that there is also a test. php. Is it the same as the original test. php? Open it with the editing software and you can see that it is no longer the original content, as shown in 2. Note: You must save the original code. Otherwise, you will be lost and cannot view or modify the code yourself.
Next, test the encrypted code and access the encrypted PHP program from the browser. Oh, an error occurred. The Code cannot run and the information shown in 3 is displayed. Originally, the PHP program encrypted with Zend guard still needs a partner-Zend optimizer to run normally and improve efficiency. You can download and install the SDK from http://www.zend.com/en/products/guard. During installation, "choose the PHP. INI folder "indicates setting the PHP configuration file on the system. INI location. The "Choose the web server's root folder" Step indicates setting the location of the web server software. After the installation is complete, use NotePad to open PHP. ini. At the end, we will see the following configuration information:
[Zend]
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 indicates that Zend optimizer has been successfully installed. we can restart the web server software to make Zend optimizer take effect. Note: If the used server has been installed or contains Zend optimizer, you do not need to install it again.
Now try accessing the encrypted PHP program from the browser again, and it will run normally. From the displayed information, we can see the Zend optimizer information (see figure 4 ).
Parsing Zend guard encryption principles
Let's take a look at the process to get a clear picture of Zend guard's protection principles. Use Zend guard to compile the PHP source code as the encryption code, and then run it by loading the Zend optimizer PHP. The program that is distributed to others is the encrypted code that can be executed, but without the source code, others cannot view and modify it. Therefore, we can add appropriate code in the program to check the current time of the system to see if the preset time limit has been exceeded. If the time limit has been exceeded, exit the program to prevent execution.
Zend guard works in a similar way to Java. The compiled PHP program is like a compiled Java binary code and can be run only with JVM support. Zend optimizer can be viewed as a PHP virtual machine. Zend guard works with Zend optimizer to complete compilation encryption and code execution after compilation.
License Management is a more in-depth use, which can be used to generate license files, so as to restrict the use of programs by selecting different licensing modes, for example, the number of simultaneous users, time restrictions, network segments, or specific servers. If you are interested, you can view the help files provided by Zend guard to understand the specific usage.