Developers / SDKs

PHP SDK.

PHP 8.0+ with the cURL extension. One file. Give it a page address, get the token.

1. Add the client

Save the client as Captora.php and require it from your script.

Captora.php
<?php// Captora.php: zero-dependency Captora client for PHP 8.0+ (uses the cURL extension).class CaptoraException extends Exception {}class Captora{    public function __construct(        private string $apiKey,        private string $baseUrl = "https://api.captora.me",        private int $pollSeconds = 3,        private int $timeoutSeconds = 180    ) {}    private function request(string $method, string $path, ?array $body = null): array    {        $ch = curl_init($this->baseUrl . $path);        curl_setopt_array($ch, [            CURLOPT_CUSTOMREQUEST => $method,            CURLOPT_RETURNTRANSFER => true,            CURLOPT_TIMEOUT => 60,            CURLOPT_HTTPHEADER => [                "Authorization: Bearer {$this->apiKey}",                "Content-Type: application/json",                "User-Agent: captora-php/1.0",            ],        ]);        if ($body !== null) {            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));        }        $raw = curl_exec($ch);        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);        curl_close($ch);        $data = json_decode($raw ?: "{}", true) ?? [];        if ($raw === false || $code >= 400) {            throw new CaptoraException("Captora error $code: " . ($data["error"] ?? "unknown"));        }        return $data;    }    /** Returns ["balance_paise" => ...] (100 paise = Rs 1). */    public function balance(): array    {        return $this->request("GET", "/v1/balance");    }    /**     * The simple way: give the address of a page with a captcha. Captora recognises the captcha, solves it,     * and returns its "result" array (usually ["token" => ...]). Pass "html" (the page source) in $extra for     * pages that add the captcha with JavaScript or need a login. Throws if it can't be solved (not charged).     */    public function solveUrl(string $websiteUrl, array $extra = []): array    {        return $this->wait($this->request("POST", "/v1/solve", ["websiteURL" => $websiteUrl] + $extra));    }    /** Advanced: you already know the captcha type. Waits for the task and returns its "result" array. */    public function solve(string $type, array $params): array    {        return $this->wait($this->request("POST", "/v1/tasks", ["type" => $type] + $params));    }    private function wait(array $task): array    {        $deadline = time() + $this->timeoutSeconds;        while (($task["status"] ?? "") === "processing" && time() < $deadline) {            sleep($this->pollSeconds);            $task = $this->request("GET", "/v1/tasks/" . $task["taskId"]);        }        if (($task["status"] ?? "") === "completed") {            return $task["result"];        }        throw new CaptoraException(($task["status"] ?? "") === "failed" ? "Could not be solved (refunded)" : "Timed out");    }}

2. Solve a captcha with one call

Put your API key in the CAPTORA_API_KEY environment variable (create one in your dashboard).

example.php
<?phprequire __DIR__ . "/Captora.php";$captora = new Captora(getenv("CAPTORA_API_KEY"));// Give it the page with the captcha. Captora finds the captcha and solves it.$result = $captora->solveUrl("https://example.com/login");echo $result["token"]; // submit this token with your form// Know the type already? $captora->solve("recaptcha_v2", ["websiteURL" => ..., "websiteKey" => ...])

3. That's it. No captcha type to pick

Captora recognises the captcha on the page. For pages that add it with JavaScript or sit behind a login, pass the page's HTML as well (see the docs). If you already know the type, the client has a second method for that. Every captcha we support, and its price, is on the captchas page.

Keep in mind

  • Keep your API key on your server. Never ship it in a browser or mobile app.
  • Solving can take from a few seconds to a minute or more, so run it in the background of your app.
  • Unsolved tasks raise an error and are refunded automatically.

Build once.
Connect with flexibility.