Download the PHP package captchala/captchala-php without Composer
On this page you can find all versions of the php package captchala/captchala-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download captchala/captchala-php
More information about captchala/captchala-php
Files in captchala/captchala-php
Package captchala-php
Short Description Captchala Server SDK for PHP - Validate captcha tokens server-side
License MIT
Homepage https://captcha.la
Informations about the package captchala-php
Captchala PHP SDK
Server-side SDK for validating Captcha tokens.
English | 简体中文
Installation
Quick Start
API Reference
Client::__construct(string $appKey, string $appSecret, int $timeout = 5)
Create a client instance.
$appKey- App Key (from dashboard)$appSecret- App Secret (from dashboard)$timeout- Request timeout in seconds (default: 5)
Client::validate(string $token, bool $keepToken = false, ?string $clientIp = null): ValidateResult
Validate a token.
$token- The pass_token from frontend SDK$keepToken- If true, token won't be consumed (can be validated again)$clientIp- (optional, recommended) The end-user's IP from your inbound request. Used for additional risk checks. Safe to omit.
ValidateResult Methods
| Method | Return Type | Description |
|---|---|---|
isValid() |
bool | Whether validation passed |
isOffline() |
bool | Whether this was offline verification |
isClientOnly() |
bool | Whether this is a client-only token |
getError() |
?string | Get error message |
getWarning() |
?string | Get warning message |
getChallengeId() |
?string | Get challenge ID |
getAction() |
?string | Get business action |
getUid() |
?string | User ID bound via bind_uid — verify the pass_token belongs to the expected user |
getUserIp() |
?string | End-user IP recorded at solve time (informational). |
getCaptchaArgs() |
array | Solve-context echo (platform, user_ip, referer, pkg, solved_at, risk_score). All informational. |
toArray() |
array | Convert to array |
Solve-context echo (captcha_args)
getCaptchaArgs() returns what the platform recorded at solve time — use it
for logging / your own risk scoring, never as a pass/fail gate:
Verifying bind_uid
If you issued the server_token with bind_uid = 'user_42', compare the
result against the expected user:
Client::issueServerToken(string $action, ?string $bindingIp = null, ?int $ttl = null, ?int $maxUses = null, ?string $bindUid = null): IssueResult
Mint a one-time sct_ server token. Hand the returned token to the browser
SDK via the serverToken prop — single-use, action-scoped, optionally
IP/UID-bound.
$action- Business scene (login,register,payment, …)$bindingIp- (optional) End-user IP; backend rejects token if a different IP redeems it$ttl- (optional) Lifetime in seconds; server enforces an upper bound (default 300)$maxUses- (optional) SDK retry budget; verification is still single-pass$bindUid- (optional) User ID; pair withValidateResult::getUid()on verify
IssueResult Method |
Return | Description |
|---|---|---|
isOk() |
bool | Issuance succeeded |
getToken() |
?string | The sct_<hex> server token |
getExpiresIn() |
?int | TTL in seconds |
getIssuedAt() |
?int | Unix timestamp (seconds) |
getError() |
?string | Error code |
getMessage() |
?string | Human-readable error message |
Client::moderationCheck(array $input, ?string $userId = null): ModerationResult
Multi-modal content moderation. $input is a list of {type, ...} items in
OpenAI-compatible format — text and image_url can be mixed in one call.
Client::moderationText(string $text, ?string $userId = null): ModerationResult
Convenience wrapper for plain-text moderation.
ModerationResult Method |
Return | Description |
|---|---|---|
isOk() |
bool | Request succeeded (regardless of flagged) |
isFlagged() |
bool | Upstream model verdict |
hasCategory(...$names) |
bool | True if any named category tripped |
getCategories() |
array | Map of category → bool; categories vary by upstream model |
getContentType() |
?string | 'text' / 'image' / 'mixed' |
getRaw() |
array | Full upstream payload for advanced inspection |
getError() |
?string | Error code |
getMessage() |
?string | Human-readable error message |
Token Types
| Prefix | Source | Security Level |
|---|---|---|
pt_ |
Main API | High |
offline_ |
Backup Service | Medium |
client_ |
Client-only | Low (cannot verify server-side) |
Complete Example
Laravel Integration
Testing
License
MIT
CMS plugin helpers (Captchala\Cms)
Used by CaptchaLa's CMS plugins (WordPress, Joomla, Drupal, Magento, …) — most integrators don't need these directly.
Action constants
Widget renderer
Error standardizer
All versions of captchala-php with dependencies
ext-json Version *