Professional Documents
Culture Documents
Useful Links
FAQ and Support Forums: http://support.nusphere.com/index.php NuSphere Home Page: http://www.nusphere.com NuSphere PhpED (PHP IDE) product page:
http://www.nusphere.com/products/phped.htm
-1-
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
Content
NuSphere Nu-Coder 2.0.................................................................................................................... - 1 User Guide ........................................................................................................................................ - 1 1 2 Content ............................................................................................................................................. - 2 Introduction...................................................................................................................................... - 4 2.1 2.2 2.3 3 3.1 3.2 What is Nu-Coder? ....................................................................................................................... - 4 Why do you need to encode PHP Applications? .......................................................................... - 4 Protecting PHP files with Nu-Coder .............................................................................................. - 4 Command Examples .................................................................................................................... - 5 Nu-Coder and PhpExpress support for PHP 4 and for PHP 5 ...................................................... - 5 -
Nu-Coder and PhpExpress difference ............................................................................................... - 5 Examples used in this User Guide..................................................................................................... - 5 4 5 Typical usage of Nu-Coders encoder and license manager ....................................................... - 6 Quick Start ....................................................................................................................................... - 7 5.1 5.2 6 6.1 6.2 7 7.1 7.2 7.3 7.4 7.5 7.6 Encoding PHP project using Nu-Coder Command Line Interface................................................. - 7 Deploying the files encoded with Nu-Coder.................................................................................. - 8 Functionality provided by Nu-Coder.............................................................................................. - 9 Interfacing with Nu-Coder ............................................................................................................. - 9 How to encode PHP files using Nu-Coder Command Line Interface ......................................... - 10 How to encode single PHP file ................................................................................................... - 10 How to encode PHP files in the entire directory.......................................................................... - 10 How to control the process of encoding of PHP files .................................................................. - 11 How to use License Manager generated licenses when encoding PHP files.............................. - 12 Examples:................................................................................................................................... - 12 -
Example #1...................................................................................................................................... - 12 Example #2...................................................................................................................................... - 13 Example #3...................................................................................................................................... - 13 Example #4...................................................................................................................................... - 13 Example #5...................................................................................................................................... - 13 Example #6...................................................................................................................................... - 13 8 Nu-Coder License Manager .......................................................................................................... - 14 8.1 8.2 8.3 8.4 How to generate License Manager Licenses using Nu-Coder Command Line Interface............ - 14 How to load license..................................................................................................................... - 15 How to handle expired or invalid license..................................................................................... - 16 Examples:................................................................................................................................... - 16 Syntax ............................................................................................................................................. - 14 -
Example #1...................................................................................................................................... - 16 Example #2...................................................................................................................................... - 16 9 Deploying Encoded PHP files with NuSphere PhpExpress ....................................................... - 18 9.1 Overview of NuSphere PhpExpress ........................................................................................... - 18 -
-2-
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
How to deploy NuSphere PhpExpress........................................................................................ - 18 How to use API provided by NuSphere PhpExpress to work with Nu-Coder.............................. - 18 How to monitor PHP Cache implemented by NuSphere PhpExpress ........................................ - 19 -
-3-
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
2
2.1
Introduction
What is Nu-Coder? Although the open-source distribution model is widely adopted by the PHP development community and works very well in many cases; encoding and protection of PHP source code is often critical to the distribution of commercial PHP applications. Nu-Coder is a powerful PHP Encoder that enables PHP developers to protect their PHP code from tempering and unauthorized copying. Nu-Coder converts the source code of PHP Script into compiled PHP bytecodes for both accelerated runtime performance and maximum security. When License Manager is used the content of the file gets additionally encrypted increasing the level of protection. NuSphere Nu-Coder consists of two components providing a dual layer of protection for PHP applications: PHP Encoder executable named nu-coder (or nu-coder.exe for Windows) License Manager executable named nu-licgen ( or nu-licgen.exe for Windows)
Nu-Coders PHP Encoder converts the source code of PHP Script into compiled PHP bytecodes for both accelerated runtime performance and maximum security. These scripts can be loaded and run with PhpExpress - NuSphere Free PHP accelerator that provides support for loading of PHP files encoded with Nu-Coder - NuSphere PHP Encoder and also speeds up the execution of both encoded and regular PHP files. Encoded PHP scripts are known to run at up to 120% faster than open-source scripts. Nu-Coders License Manager helps you manage the distribution of PHP applications by generating license keys that can be required by encoded files to run. Using License Manager you can create trial and demo versions of PHP applications without any code changes, restrict the IP or the host name or host id where your application can run and much more
2.2
Why do you need to encode PHP Applications? Piracy Protection: PHP developers and Independent Software Vendors (ISVs) can safely distribute their source code, knowing that their intellectual property is protected Reduced support burden: Since technical support personnel will be able to rule out PHP source code modifications Enhanced compliance: Enterprise customers can enforce internal policies and easily provide the support for a company's PHP Applications.
2.3
Protecting PHP files with Nu-Coder You can encode PHP files using Nu-Coder's powerful command line interface or from within the user interface provided by NuSphere PhpED. Your users will need NuSphere PhpExpress to deploy and run the encoded PHP Files. PhpExpress is available for free download and distribution. PhpExpress is also built in NuSphere PhpDock, which now fully supports deployment of encoded PHP applications. PhpExpress also provides API in form of PHP functions that can be called to retrieve various information.
-4-
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
3.1
Command Examples Command line text in the User Guide is printed in monospace bold font. Command examples are printed in the form:
prompt> nu-coder -v NuSphere PHP Encoder Nu-Coder 2.0.0 Copyright (c) 2005-2008 NuSphere Corp.
Or similar with License Manager
prompt> nu-licgen -v NuSphere Nu-Coder license generator 2.0.0 Copyright (c) 20052008 NuSphere Corp.
Shell input is shown in bold, and program output is plain. prompt> is an example shell prompt for command entry but this may be different on your own system. 3.2 Nu-Coder and PhpExpress support for PHP 4 and for PHP 5
-5-
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
-6-
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
Quick Start
This chapter introduces some of the most common features of the Command Line Interface to Nu-Coder PHP Encoder, with quick-start examples for typical scenarios. For PhpED users, it also describes the PhpED GUI for Nu-Coder. Detailed description of NuCoder CLI and PhpED GUI for Nu-Coder is given in subsequent chapters of this User Guide.
5.1
Encoding PHP project using Nu-Coder Command Line Interface You can encode php files in the entire project using directory processing mode of NuCoder. In the following example we will assume that your Project root (or top) Windows directory is C:\Program Files\nusphere\project-dir\web. To encode the files in C:\Program Files\nusphere\project-dir\web and all of it subdirectories you need to: Install NuSphere Nu-Coder Open a Command Window (Run->cmd) Type at the prompt:
-7-
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
5.2
Deploying the files encoded with Nu-Coder At this point you can deploy encoded PHP files stored in the directory C:\Program Files\nusphere\project-dir\web-encoded with any PHP interpreter running PhpExpress NuSphere Free PHP loader and accelerator that provides support for encoded files and also speeds up the execution of regular PHP files. Simple procedure of installing PhpExpress is described in section 8.2 of this User Guide. Note: If an attempt is made to execute the files encoded with Nu-Coder on the system without PhpExpress installed, the system will search for PhpExpress module in the web folders under Document Root (recursively) and try to load it if found. If PhpExpress is not found there as well, then the system will display a warning message to the user, saying that PhpExpress is not installed and referring the User to PhpExpress download website. Please note that you can also: Use version-1.4 compatible header (--nodl command line argument) in this case the search for PhpExpress wont be performed and the error will be generated immediately Encode the file without the header using --noheader command line option. In this case the server will use the default file handler to serve the encoded script Use custom header (--header command line option) and take control over the handling of this situation
-8-
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
6
6.1
6.2
Interfacing with Nu-Coder NuSphere provides two different interfaces with Nu-Coder: Command Line Interface to a standalone Nu-Coder Graphical User Interface to Nu-Coder from PhpED, NuSphere PHP IDE Both interfaces allow the user to pass various parameters to the encoder to control the way PHP Sources are compiled into bytecodes and the creation of output files. Using either of these interfaces you can: Specify the PHP version of the files that are being encoded Encode and protect PHP files in the entire given directory and its sub-directories Encode single PHP file and save results into output file. Tell Nu-Coder to create output files name by appending given extension at the end of the source file name Overwrite the source file with encoded content Perform Syntax check only and not produce any encoded content In directory processing mode, encode only files with certain extensions (defaults are php and inc) Copy all non-php files into target directory Ignore errors and continue encoding Turn off support for short php tags <? ?> Turn on support for asp style php tags <% %> Keep extended information for php debugger and php profiler Preserve line numbers information Preserve and not strip php-doc comments, useful for reflection Create license files required to run encoded PHP scripts Skip encoding of certain files and folders or encode them but not protect with the license Obfuscate the source (change the names of the variables) Specify the script to be called to handle an error (e.g. expired license) Changed the files headers
-9-
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
7.1
How to encode PHP files using Nu-Coder Command Line Interface Nu-Coder can be invoked with various options entered on the Command Line. This section presents the syntax and required arguments for using Nu-Coder administration commands. The commands are case-sensitive.
Syntax
nu-coder.exe nu-coder.exe nu-coder.exe nu-coder.exe nu-coder.exe [options] [options] [options] [options] [options] directory targetdir [-f] file targetfile --appendext ext fileordirectory --overwrite fileordirectory
7.2
How to encode single PHP file You can run Nu-Coder in single file processing mode by specifying the source file and target file at the end of the command line:
nu-coder.exe [options] f source-file target-file When started with this command Nu-Coder will encode the source-file and save results into target-file.
Please note that some options are available in both directory and single file processing modes. For example, option --appendext <ext> is used to append <ext> at the end of source file name. This option can be used in both single file and directory processing mode and will cause Nu-Coder to append <ext> to a single files name or to all files in the source directory respectively.
7.3
How to encode PHP files in the entire directory You can run Nu-Coder in directory processing mode by specifying the source directory and target directory at the end of the command line:
- 10 -
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
--ext <extlist>
--exclude <files>
All other options are available in both directory and single file processing modes. 7.4 How to control the process of encoding of PHP files Nu-Coder interface provides various options to control what the program does and how it does it. Below is the table of Administration options of Nu-Coder Command Line Interface:
Specify the version of PHP scripts to be encoded. If omitted, the encoding will be done for PHP 5.1 Perform syntax check only, do not produce any encoded content Do not stop on errors Turn off support for short php tags <? ?> Turn on support for asp style php tags <% %> Keep extended information for debugger/ profiler. This option also automatically turns on -lineinfo option, which preserves line numbers information Preserves line numbers information Do not strip php-doc comments, useful for reflection Display this help Suppress all normal output Version number apply obfuscation supported level 1 variables will be Use custom header before encoding. Currently means that name of all local replaced with generated ones from file <fname> instead of built-in one
-c <PHP version> -s, --syntax-check -n, --noerrors -t, --noshorttags -a, --asptags
-e
--lineinfo --phpdoc -h, --help -q, --quiet -v, --version -b <level>, --obfuscation <level> -d, --header <fname>
- 11 -
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
--nodl --noheader
Do not use the default auto-loading header Do not add any headers
7.5
How to use License Manager generated licenses when encoding PHP files Nu-Coders License Manager allows you to generate license files, which will be required for your PHP application to run. Below is the table of options available to encode PHP files with license files generated by Nu-Coder License manager. The list of the options available for License Manager is described in later sections of this manual.
Protect encoded files with license generated with <keyword>. Generated encoded files will require appropriate license file to be loaded either in php configuration or at runtime. The license should be generated with the same keyword. Licenses generated with another keywords will be ignored Exclude specified files from any licensing protection Tells PhpExpress to automatically load the license <filename> for the file(s) encoded with this option. Otherwise license should be loaded with the call to pelm_load_license()or by using
--excludelic <files>
--licfile <filename>
Please note that if --licfile option is not used during encoding process and you still want to use licenses with your PHP applications, you need to call function pelm_load_license()explicitly in PHP code or use the following instruction in php.ini file:
phpexpress.add_license=license1.txt license2.txt
7.6
Examples: The following are some examples of using Nu-Coder Command Line Interface to encode PHP files :
Example #1
Encode files in the directory c:\myproject\source and all of its subdirectories recursively and place the resulting encoded files in the directory c:\myproject\source-enc, without changing the names of the files:
- 12 -
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
Example #2
Encode files with extension .phtml in the directory c:\myproject\source and all of its subdirectories recursively and place the resulting encoded files in the same directory. c:\myproject\source-enc, without changing the names of the files:
Example #3
Encode single file c:\myproject\index.php and store the resulting encoded file in c:\myproject\index.php.enc:
Example #4
Encode single file c:\myproject\index.php and append .enc to the extension of the resulting file (i.e. make it c:\myproject\index.php.enc)
Example #5
Encode files in the directory c:\myproject\source and all of its subdirectories recursively and place the resulting encoded files in the directory c:\myproject\source-enc, without changing the names of the files. Also copy all non-php files to c:\myproject\source-enc except for those in CVS and SVN directories and the drawings (*.dwg)
Example #6
Encode single file c:\myproject\index.php and obfuscate the code in it by replacing the names of the variables with generated ones
- 13 -
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
8.1
How to generate License Manager Licenses using Nu-Coder Command Line Interface The interface to Nu-Coders License Manager provides you with multiple options to generate License files for encoded PHP scripts. The similar syntax is used for generation of the License files as it is for encoding of php files, however the name of the executable is different. See how to encode the files to use generated licenses in the section How to use License Manager generated licenses when encoding of PHP files of this manual
Syntax
nu-licgen [options]
The following are the options used by Nu-Coders License Manager
-k <keyword>, --key <keyword> generate license with provided keyword. It's recommended to use keywords of 6-16 or more alphanumeric characters. It's necessary to encode PHP files with the same keyword or license will be ignored. add custom header to the license file create attribute(s) to be stored in license file. These attributes all are encrypted with the license key. attributes can be read from the license at runtime with pelm_get_attribute() function call. make attribute's copy visible in the license
- 14 -
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
--lid <id>
--lmac <mac>
lock the license into server hardware identified by specified host ID(s).(See PhpExpress API on how to get host IDs). If multiple IDs are specified, license will require at least one ID to match server hardware lock license into server hardware identified by specified Ethernet MAC addrress(es). For example --lmac 00-C0-44-11-33-A4,00-C0-44-1133-A5 lock the license into server software settings. License will work only for servers accessed with specified IP address(es). Wildcards are acceptable, for example --lip 217.217.217.5,217.217.216.* lock the license into server software settings. License will work only for accessed with specified host name(s). Wildcards are acceptable, for example --lvhost *.mydomain.com,mydomain.com
--lip <ip>
--lvhost <vhost>
--ldate <mm/dd/yyyy>
set license expiration date. Generated license will stop working after it is expired and PHP script will stop running. Useful for creation of demo versions and trials. The date must be set in the future alternative way of specifying license expiration date. Specified period should be at least one day long
--lperiod <days>
8.2
PHP scripts protected by the license will only run if the corresponding valid license file is loaded. You can load the License in one of the following ways: Load license in php.ini file using the instruction: phpexpress.add_license = license1.txt, license2.txt This instruction is applicable to each virtual host, therefore different virtual hosts can use different licenses. Load license in .htdocs file using the instruction (will only work with php module of Apache): php_value phpexpress.add_license "license3.txt" In a file not protected by the license call the function pelm_load_license("license4.txt"). While the file containing this call can not be license protected it can still be encoded. pelm_load_license() function is a part of PhpExpress API
- 15 -
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
Specify the name of the license file at the time of the encoding. For example:
Example #1
Generate license for an evaluator of the PHP application:
nu-licgen -k "super-store 1.1 trial" -a caption="super-store version 1.1" x caption --lperiod 14 license_name.txt
Generated license file license_name.txt will be good for 14 days from the moment of creation and will have one attribute called caption. Attribute caption is going to be visible in the license file. To protect PHP files in c:\myproject\source with license_name.txt (generated with the command shown above) the following syntax should be used for encoding:
Example #2
Generate the license for commercial PHP application and link it to host id HVCE42C61936X (host id should be obtained from the client. PhpExpress provides API function phpexpress_hostid() that can be used for this purpose, described later in the this manual)
- 16 -
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
nu-licgen -k "1.1 super-store commercial" -a caption=" super-store version 1.1",licensee="John Doe" -x caption,licensee --lid HVCE42C-61936X license_name.txt
In this example, the license file generate will allow the execution of PHP files only on the host id HVCE42C-61936X. To link PHP files from c:\myproject\source to license_name.txt the following syntax should be used for encoding (same as in the Example #1 of this section):
- 17 -
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
9
9.1
9.2
How to deploy NuSphere PhpExpress NuSphere PhpExpress is a regular PHP extension, which makes it easy to install and deploy. To install PhpExpress: Open php.ini file for editing Add line zend_extension_ts=c:\full\path\to\phpexpress-php-x.x.dll if you are deploying on Windows, or zend_extension=/full/path/to/phpexpress-php-x.x.so if you are deploying on Unix, Linux or Mac OS operating systems Copy phpexpress-php-x.x.dll or phpexpress-php-x.x.so in the PHP extensions directory specified in php.ini file Stop and Start Apache if you are running PHP as Apache module Execute call to phpinfo() function and make sure that PhpExpress is properly installed Once PhpExpress is installed on the server, you can execute PHP Scripts encoded with Nu-Coder as well as regular, not encoded PHP scripts. In both cases you will gain an improved performance in the execution of the scripts.
9.3
How to use API provided by NuSphere PhpExpress to work with Nu-Coder PhpExpress provides a number of PHP Functions useful when encoding PHP files with and without Nu-Coders License Manager. The following functions are likely to be used by the users deploying files encoded with PHP Enoder:
- 18 -
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
void phpexpress() shows phpexpress info page. array phpexpress_hostid(); returns the list of host IDs that identify server hardware. Note: all host IDs are shown on the PhpExpress info page. It's recommended to use ALL host IDs that are found on the system. It will make license less sensitive to the hardware changes. The following functions are likely to be used by PHP developers deploying their PHP applications encoded by Nu-Coder: bool pelm_is_licensed(); returns true if caller script is protected with license bool pelm_load_license(string filename); loads license and returns true if file is found. NOTE: if relative path name is specified, PhpExpress will use include_path php setting to find the file. For further details about include_path see php manual. string pelm_license_filename() returns license filename that is applied to the caller script. It returns false if no license is used. string pelm_get_attribute(string attr_name); reads attribute value from the license applied to the caller script. It returns false if no license is used. pe_handle_error($errcode, $errmessage, $licfilename) gets called if the license is not found, expired or not valid for any other reason. Possible error codes are: PE_ERR_NO_LIC no licenses found PE_ERR_NO_VALID_LIC the license is found but it is not applicable for this application PE_ERR_EXPIRED_LIC license is expired PE_ERR_HOST_MISMATCH_LIC license doesnt match the host (by IP or HTTP host) PE_ERR_HW_MISMATCH_LIC license is generated for a different hostid
9.4
How to monitor PHP Cache implemented by NuSphere PhpExpress PhpExpress accelerates execution of PHP scripts by caching them and avoiding unnecessary compilation. You can view and control PHP Cache created by PhpExpress with a single function call to the PHP function phpexpress() provided by PhpExpress PHP extension. phpexpress() produces the output similar to phpinfo() with the user Interface to administer PhpExpress cache. The output of phpexpress() is illustrated below:
- 19 -
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
Please note that PHP caching is only enabled when PHP is running as an extension of the Web Server dll on windows or shared object on Linux/Unix/Mac Operating Systems. Caching of PHP scripts when PHP is running in CGI mode is not useful and therefore disabled.
- 20 -
Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.
- 21 -