Bypass captcha with PHP

Integrate PHP package for bypass captcha automation solution. Best successful captcha recognition rate.

PHP package for easy integration with the API of 2Captcha captcha solving service to bypass reCAPTCHA, hCaptcha, Arkose captcha, Geetest and solve any other captchas

Quick start

Installation

The script package can be installed using the package installer or manually

Composer

To automatically install a package of libraries, you need to use the standard solution for PHP packages - Composer. Download it from the link and install according to the instructions. After installing the application, use the command:

composer require 2captcha/2captcha

Manual

Download the contents of the src folder to your project and activate the src/autoloader.php autoloader with the command:

require 'path/to/autoloader.php';

We invite you to explore our GitHub repository where you can find libraries and modules for easy integration with our API.

Configuration

Description of all the necessary parameters to configure the installed package

An instance of the TwoCaptcha class can be created like this:

$solver = new \TwoCaptcha\TwoCaptcha('YOUR_API_KEY');

You also have the ability to customize some of the options for the created instance:

$solver = new \TwoCaptcha\TwoCaptcha([
    'apiKey'           => 'YOUR_API_KEY',
    'softId'           => 123,
    'callback'         => 'https://your.site/result-receiver',
    'defaultTimeout'   => 120,
    'recaptchaTimeout' => 600,
    'pollingInterval'  => 10,
]);
TwoCaptcha instance options
OptionDefault valueDescription
softId-your software ID obtained after publishing in 2Captcha software catalog
callback-URL of your web-sever that receives the captcha recognition result. The URL should be first registered in pingback settings of your account
defaultTimeout120Polling timeout in seconds for all captcha types except reCAPTCHA. Defines how long the module tries to get the answer from res.php API endpoint
recaptchaTimeout600Polling timeout for reCAPTCHA in seconds. Defines how long the module tries to get the answer from res.php API endpoint
pollingInterval10Interval in seconds between requests to res.php API endpoint, setting values less than 5 seconds is not recommended
IMPORTANT: once callback is defined for TwoCaptcha instance, all methods return only the captcha ID and DO NOT poll the API to get the result. The result will be sent to the callback URL. To get the answer manually use getResult method

Solve captcha

When you submit any image-based captcha use can provide additional options to help 2Captcha workers to solve it properly

Captcha options
OptionDefault valueDescription
numeric0Defines if captcha contains numeric or other symbols see more info in the API docs
minLength0minimal answer length
maxLength0maximum answer length
phrase0defines if the answer contains multiple words or not
caseSensitive0defines if the answer is case sensitive
calc0defines captcha requires calculation
lang-defines the captcha language, see the list of supported languages
hintImg-an image with hint shown to workers with the captcha
hintText-hint or task text shown to workers with the captcha

To bypass a normal captcha (distorted text on image) use the following method. This method also can be used to recognize any text on the image.

$result = $solver->normal('path/to/captcha.jpg');

This method can be used to bypass a captcha that requires to answer a question provided in clear text.

$result = $solver->text('If tomorrow is Saturday, what day is today?');

Use this method to solve reCAPTCHA V2 and obtain a token to bypass the protection.

$result = $solver->recaptcha([
    'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
    'url'     => 'https://mysite.com/page/with/recaptcha',
]);

This method provides reCAPTCHA V3 solver and returns a token.

$result = $solver->recaptcha([
    'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
    'url'     => 'https://mysite.com/page/with/recaptcha',
    'version' => 'v3',
]);

FunCaptcha (Arkoselabs) solving method. Returns a token.

$result = $solver->funcaptcha([
    'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
    'url'     => 'https://mysite.com/page/with/funcaptcha',
]);

Method to solve GeeTest puzzle captcha. Returns a set of tokens as JSON.

$result = $solver->geetest([
    'gt'        => 'f1ab2cdefa3456789012345b6c78d90e',
    'challenge' => '12345678abc90123d45678ef90123a456b',
    'url'       => 'https://www.site.com/page/',
]);

Use this method to solve hCaptcha challenge. Returns a token to bypass captcha.

$result = $solver->hcaptcha([
    'sitekey'   => '10000000-ffff-ffff-ffff-000000000001',
    'url'       => 'https://www.site.com/page/',
]);

Token-based method to solve KeyCaptcha.

$result = $solver->keycaptcha([
    's_s_c_user_id'          => 10,
    's_s_c_session_id'       => '493e52c37c10c2bcdf4a00cbc9ccd1e8',
    's_s_c_web_server_sign'  => '9006dc725760858e4c0715b835472f22-pz-',
    's_s_c_web_server_sign2' => '2ca3abe86d90c6142d5571db98af6714',
    'url'                    => 'https://www.keycaptcha.ru/demo-magnetic/',
]);

Token-based method to bypass Capy puzzle captcha.

$result = $solver->capy([
    'sitekey' => 'PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v',
    'url'     => 'http://mysite.com/',
    'api_server' => 'https://jp.api.capy.me/',
]);

Grid method is originally called Old reCAPTCHA V2 method. The method can be used to bypass any type of captcha where you can apply a grid on image and need to click specific grid boxes. Returns numbers of boxes.

$result = $solver->grid('path/to/captcha.jpg');

Canvas method can be used when you need to draw a line around an object on image. Returns a set of points' coordinates to draw a polygon.

$result = $solver->canvas('path/to/captcha.jpg');

ClickCaptcha method returns coordinates of points on captcha image. Can be used if you need to click on particular points on the image.

$result = $solver->coordinates('path/to/captcha.jpg');

This method can be used to solve a captcha that asks to rotate an object. Mostly used to bypass FunCaptcha. Returns the rotation angle.

$result = $solver->rotate('path/to/captcha.jpg');

Other methods

Additional valid methods used during the work of the main scripts

send / getResult

These methods can be used for manual captcha submission and answer polling.

$id = $solver->send(['file' => 'path/to/captcha.jpg', ...]);

sleep(20);

$code = $solver->getResult($id);

balance

Use this method to get your account's balance.

$balance = $solver->balance();

report

Use this method to report good or bad captcha answer.

$solver->report($id, true); // captcha solved correctly
$solver->report($id, false); // captcha solved incorrectly

Error handling

Possible variants of standard errors returned by the service when processing requests

If case of an error captcha solver throws an exception. It's important to properly handle these cases. We recommend to use try/catch to handle exceptions.

try {
    $result = $solver->text('If tomorrow is Saturday, what day is today?');
} catch (\TwoCaptcha\Exception\ValidationException $e) {
    // invalid parameters passed
} catch (\TwoCaptcha\Exception\NetworkException $e) {
    // network error occurred
} catch (\TwoCaptcha\Exception\ApiException $e) {
    // api respond with error
} catch (\TwoCaptcha\Exception\TimeoutException $e) {
    // captcha is not solved so far
}

Other languages for integration with the service API