PHP code example of capmonstercloud / capmonster-client

1. Go to this page and download the library: Download capmonstercloud/capmonster-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

capmonstercloud / capmonster-client example snippets



CapMonsterCloud\CapMonsterClient;
use CapMonsterCloud\ClientOptions;
use CapMonsterCloud\Requests\ImageToTextRequest;
use CapMonsterCloud\Requests\RecaptchaV2Request;
use CapMonsterCloud\Requests\TurnstileRequest;

$client = new CapMonsterClient(new ClientOptions('your_client_key'));

// check balance
echo $client->getBalance(), PHP_EOL;

// solve image captcha
$imageResult = $client->solve(ImageToTextRequest::fromFile('captcha.png'));
echo $imageResult['text'], PHP_EOL;

// solve reCAPTCHA v2 (without proxy)
$recaptchaV2Result = $client->solve(new RecaptchaV2Request(
    'https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high',
    '6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd',
));
echo $recaptchaV2Result['gRecaptchaResponse'], PHP_EOL;

// solve Cloudflare Turnstile (without proxy)
$turnstileResult = $client->solve(TurnstileRequest::standard(
    'https://target-website.com/login',
    '0x4AAAAAAABnPIDnK2k_e-2',
));
echo $turnstileResult['token'], PHP_EOL;

use CapMonsterCloud\Exception\CapMonsterException;
use CapMonsterCloud\Exception\GetResultException;
use CapMonsterCloud\Exception\TimeoutException;

try {
    $solution = $client->solve($request);
} catch (GetResultException $e) {
    // the API returned an error, e.g. $e->errorCode === 'ERROR_CAPTCHA_UNSOLVABLE'
} catch (TimeoutException $e) {
    // no solution within the maximum waiting time of this captcha type
} catch (CapMonsterException $e) {
    // anything else: invalid request, network error, wrong key, zero balance...
}

// Before: 2Captcha
$solver = new \TwoCaptcha\TwoCaptcha('YOUR_2CAPTCHA_API_KEY');
$result = $solver->recaptcha([
    'sitekey' => 'YOUR_SITE_KEY',
    'url'     => 'https://target-website.com/page-with-recaptcha',
]);
$token = $result->code;


CapMonsterCloud\CapMonsterClient;
use CapMonsterCloud\ClientOptions;
use CapMonsterCloud\Exception\CapMonsterException;
use CapMonsterCloud\Requests\RecaptchaV2Request;

$client = new CapMonsterClient(new ClientOptions('YOUR_CAPMONSTER_API_KEY'));

$request = new RecaptchaV2Request(
    'https://target-website.com/page-with-recaptcha',
    'YOUR_SITE_KEY',
);

try {
    $token = $client->solve($request)['gRecaptchaResponse'];
    echo $token;
} catch (CapMonsterException $e) {
    echo $e->getMessage();
}
text
[ Your PHP script ]
         │
         ▼
[ Extract sitekey & website URL ]
         │
         ▼
[ CapMonster Cloud PHP SDK ] ──► createTask API request
         │
         ▼
[ Neural Network Processing ] ──► Poll getTaskResult until the task is ready
         │
         ▼
[ Receive Token & Autosubmit ] ──► Complete bypass