Debugging of scripts which work with encoded templates

Top  Previous  Next

Usually the SourceGuardian API function are not available until SourceGuardian is loaded by the protected script. The exception to this is when the SourceGuardian loader is installed server-wide in php.ini. It may be not obvious how to debug scripts using the SourceGuardian API because of this. For convenience and easy debugging we suggest two possible way for debugging scripts which use the SourceGuardian encoding API:

 

1) Install an appropriate SourceGuardian loader server-wide in php.ini as a PHP extension. Usually it's possible to do on development machine as normally PHP installation is over developer's control there. With using this way SourceGuardian API functions will be always available. When called from the unencoded source scripts sg_encode_file() and sg_load_file() functions are both work with unprotected data for reading and writing and so it's easy to debug and check content of the output file or loaded template file etc. When project debugging is finished and project is encoded, SourceGuardian API functions will start working in normal (protected) mode with reading and writing encoded templates/non-PHP files data.

 

2) Use our SourceGuardian API stub script sgapistub.php (http://sourceguardian.com/scripts/sgapistub.php)  This is very simple PHP script which simulates sg_load_file() and sg_encode_file() functions without doing any encoding or decoding. When run from protected script and SourceGuardian API functions are available this script does nothing and lets real API functions to work. To use this stub script you need to include it from your script which uses SourceGuardian encoding API. When running from unprotected script, functions defined in this stub script will read and write templates or data files as-is which lets to debug the script and check content of the output file or loaded template file. When project debugging is finished and project is to be encoded with SourceGuardian you need to encode the stub script with all other PHP scripts in your project. When run from the protected script the stub file itself will do nothing as real SourceGuardian API functions will be used. This is done for convenience and you don't need to search your scripts and remove or comment the include operator which includes the stub script. Please read comments in the beginning of sgapistub.php script before using.

 

Please feel free to choose the better way for you for debugging your protected scripts. The second method does not require to have access to php.ini even in development environment.