|
Custom error handling |
Top Previous Next |
|
You may add custom error handling functions which will catch script licensing errors. Error handler should be a function which accepts two parameters:
sg_error_handler( code , message )
You may use any name for this function. Also you may have different functions for different script errors. The first argument will contain an error code. The second one will contain a default error message.
To set a custom error handler use --catch option in encode4 or encode5 command:
encode4 --catch err=function myscript.php
Where "err" is one of predefined constants and "function" is error handler function name.
ERR_ALL is a special value to specify "one-for-all" error handler function.
Custom error handler function should be defined before an error may occur. The best place for it is in "prepend header" code as it's loaded *before* any license checking is done and so error handler will be always available if defined here. But you may also define a custom error handler function in another encoded file which will be included before the script which may cause a license error. Don't put any passwords etc secret data if you use a "prepend header" code for defining an error handler as this code is stored unencoded.
* Custom error handling with standard PHP error handling mechanism
You may catch some SourceGuardian errors with the standard PHP error handling mechanism. This may be useful if you already have an error handler in your code. Below is an example of an error handler to catch SourceGuardian errors.
<?php function myErrorHandler($errno, $errmsg, $filename, $linenum, $vars) { if ($errno & E_NOTICE) return; if(strstr($errmsg, 'SourceGuardian')) { $code = substr($errmsg, strrpos($errmsg,'[')+1,2); echo "SourceGuardian error $code"; } else echo $errmsg; } error_reporting(E_ERROR); set_error_handler("myErrorHandler"); ?>
|