Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Protecting Your PHP Source Code With ionCube Encoder

Encoding Your PHP Files

The ionCube PHP Encoder is a command-line script you run either one or more files, or on an entire set of folders. If you're encoding an entire PHP application you would typically run it on the original source folder. The encoder will duplicate the entire tree, except the PHP code will be encoded.

In the previous section I showed you what the encoded PHP code from a basic "Hello World" script looks like. The command I used to generate this encoded script is as shown in Listing 3.

Listing 3 Basic usage of the encoder (listing-3.txt)
/usr/local/ioncube/ioncube_encoder5 helloworld.php -o helloworld-enc.php

In this example, the -o specified the output location. In this example I just created the encoded file in the same directory with a different filename. Typically you would want to create the file with the same filename as the original (without replacing the original source code).

To achieve this, set the input and output both to be a directory. The encoder will automatically recurse through all directories in the input directory and encode all PHP files.

To demonstrate this, let's assume helloworld.php is in a directory called src. Listing 4 shows the command we use to encode this entire path. The example outputs the encoded files to the build directory.

Listing 4 Encoding an entire directory (listing-4.txt)
/usr/local/ioncube/ioncube_encoder5 src -o build

We now have a directory called build which is identical to src except that the PHP files are encoded.

Note: Even non-PHP files (such as images or stylesheets) are also copied as-is into the target directory.

There are many other command-line options. You can discover some of these by running ioncube_encoder5 with no arguments. Additionally, the "Encoder User Guide API" document (available from here) is extremely useful.

In This Article