Castle analyzes user behavior in web and mobile apps to stop fraud before it happens.
See the documentation for how to use this SDK with the Castle APIs
Obtain the latest version of the Castle PHP bindings with:
git clone --single-branch --branch master https://github.com/castle/castle-php
To get started, add the following to your PHP script:
Configure the library with your Castle API secret.
Set preferred connection and request timeouts: valid options for setting are:
Set a specified list of request headers to include with event context (optional, not recommended):
By default, Castle extracts all the necessary information, such as IP and request headers, from the PHP globals in order to build and send the requests to the Castle API. However in some cases you want to track data to Castle from a context where these globals are not available, eg. when tracking async in a background worker. In this case you can build the request context manually.
By default, the SDK extracts the contextual client IP address from headers in the following priority:
If the true client IP address is not specified in the above headers, you can manually set the IP address like so:
Castle_RequestContext['ip'] = '188.8.131.52' $context = Castle_RequestContext::extractJson();
Whenever something unexpected happens, an exception is thrown to indicate what went wrong.
||A generic error|
||A request failed. Probably due to a network error|
||An unexpected error for the Castle API|
||The Castle secret API key has not been set|
||Wrong Castle API secret key|
||The request was invalid. For example if a challenge is created without the user having MFA enabled.|
||The user has entered the wrong code too many times and a new challenge has to be requested.|
||The resource requestd was not found. For example if a session has been revoked.|
||One or more of the supplied parameters are incorrect. Check the response for more information.|
||The request token parameter is missing or invalid|
vendor/bin/phpunit test to run the full test suite