Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/2captcha/2captcha-php
PHP package for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, funcaptcha, Cloudflare turnstile, geetest and solve any other captchas.
https://github.com/2captcha/2captcha-php
2captcha anti-captcha anticaptcha bypass-invisible-recaptcha bypass-on-captcha-recaptcha bypass-recaptcha-v2 bypasscaptcha captcha-breaking captcha-bypass captcha-recognition captcha-services-for-recaptcha-v2 captcha-solver captcha-solving cloudflare-turnstile-solver deathbycaptcha google-recaptcha-solver recaptcha-solver recaptcha-solver-php recaptcha-v2-captcha-solver
Last synced: 4 days ago
JSON representation
PHP package for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, funcaptcha, Cloudflare turnstile, geetest and solve any other captchas.
- Host: GitHub
- URL: https://github.com/2captcha/2captcha-php
- Owner: 2captcha
- License: mit
- Created: 2020-05-15T12:52:49.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-12-06T02:26:04.000Z (about 1 month ago)
- Last Synced: 2024-12-29T08:04:54.410Z (11 days ago)
- Topics: 2captcha, anti-captcha, anticaptcha, bypass-invisible-recaptcha, bypass-on-captcha-recaptcha, bypass-recaptcha-v2, bypasscaptcha, captcha-breaking, captcha-bypass, captcha-recognition, captcha-services-for-recaptcha-v2, captcha-solver, captcha-solving, cloudflare-turnstile-solver, deathbycaptcha, google-recaptcha-solver, recaptcha-solver, recaptcha-solver-php, recaptcha-v2-captcha-solver
- Language: PHP
- Homepage: https://2captcha.com
- Size: 420 KB
- Stars: 74
- Watchers: 6
- Forks: 47
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Module for 2Captcha API (captcha solver)
The easiest way to quickly integrate [2Captcha] captcha solving service into your code to automate solving of any types of captcha.
Examples of API requests for different captcha types are available on the [PHP captcha solver] page.
- [PHP Module for 2Captcha API (captcha solver)](#php-module-for-2captcha-api-captcha-solver)
- [Installation](#installation)
- [Composer](#composer)
- [Manual](#manual)
- [Configuration](#configuration)
- [TwoCaptcha instance options](#twocaptcha-instance-options)
- [Solve captcha](#solve-captcha)
- [Captcha options](#captcha-options)
- [Normal Captcha](#normal-captcha)
- [Text Captcha](#text-captcha)
- [reCAPTCHA v2](#recaptcha-v2)
- [reCAPTCHA v3](#recaptcha-v3)
- [FunCaptcha](#funcaptcha)
- [GeeTest](#geetest)
- [GeeTest V4](#geetest-v4)
- [KeyCaptcha](#keycaptcha)
- [Capy](#capy)
- [Grid](#grid)
- [Canvas](#canvas)
- [ClickCaptcha](#clickcaptcha)
- [Rotate](#rotate)
- [Audio Captcha](#audio)
- [Yandex](#yandex)
- [Lemin Cropped Captcha](#lemin-cropped-captcha)
- [Cloudflare Turnstile](#cloudflare-turnstile)
- [Amazon WAF](#amazon-waf)
- [Tencent](#tencent)
- [MTCaptcha](#mtcaptcha)
- [Cutcaptcha](#cutcaptcha)
- [Friendly Captcha](#friendly-captcha)
- [atbCAPTCHA](#atbcaptcha)
- [DataDome](#datadome)
- [CyberSiARA](#cybersiara)
- [Other methods](#other-methods)
- [send / getResult](#send--getresult)
- [balance](#balance)
- [report](#report)
- [Proxies](#proxies)
- [Error handling](#error-handling)
- [Examples](#examples)
- [Get in touch](#get-in-touch)
- [Join the team 👪](#join-the-team-)
- [License](#license)
- [Graphics and Trademarks](#graphics-and-trademarks)## Installation
This package can be installed via composer or manually### Composer
```
composer require 2captcha/2captcha
```### Manual
Copy `src` directory to your project and then `require` autoloader (`src/autoloader.php`) where needed:
```php
require 'path/to/autoloader.php';
```## Configuration
`TwoCaptcha` instance can be created like this:
```php
$solver = new \TwoCaptcha\TwoCaptcha('YOUR_API_KEY');
```
Also there are few options that can be configured:
```php
$solver = new \TwoCaptcha\TwoCaptcha([
'server' => 'http://rucaptcha.com',
'apiKey' => 'YOUR_API_KEY',
'softId' => 123,
'callback' => 'https://your.site/result-receiver',
'defaultTimeout' => 120,
'recaptchaTimeout' => 600,
'pollingInterval' => 10,
]);
```### TwoCaptcha instance options
| Option | Default value | Description |
| ---------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| softId | 4585 | 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 |
| defaultTimeout | 120 | Polling timeout in seconds for all captcha types except reCAPTCHA. Defines how long the module tries to get the answer from `res.php` API endpoint |
| recaptchaTimeout | 600 | Polling timeout for reCAPTCHA in seconds. Defines how long the module tries to get the answer from `res.php` API endpoint |
| pollingInterval | 10 | Interval 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](#send--getresult)
## Solve captcha
When you submit any image-based captcha use can provide additional options to help 2captcha workers to solve it properly.### Captcha options
| Option | Default Value | Description |
| ------------- | ------------- | -------------------------------------------------------------------------------------------------- |
| numeric | 0 | Defines if captcha contains numeric or other symbols [see more info in the API docs][post options] |
| minLength | 0 | minimal answer length |
| maxLength | 0 | maximum answer length |
| phrase | 0 | defines if the answer contains multiple words or not |
| caseSensitive | 0 | defines if the answer is case sensitive |
| calc | 0 | defines 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 |Below you can find basic examples for every captcha type. Check out [examples directory] to find more examples with all available options.
### Normal Captcha
[API method description.](https://2captcha.com/2captcha-api#solving_normal_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.
```php
$result = $solver->normal('path/to/captcha.jpg');
```### Text Captcha
[API method description.](https://2captcha.com/2captcha-api#solving_text_captcha)
This method can be used to bypass a captcha that requires to answer a question provided in clear text.
```php
$result = $solver->text('If tomorrow is Saturday, what day is today?');
```### reCAPTCHA v2
[API method description.](https://2captcha.com/2captcha-api#solving_recaptchav2_new)
Use this method to solve reCAPTCHA V2 and obtain a token to bypass the protection.
```php
$result = $solver->recaptcha([
'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
'url' => 'https://mysite.com/page/with/recaptcha',
]);
```### reCAPTCHA v3
[API method description.](https://2captcha.com/2captcha-api#solving_recaptchav3)
This method provides reCAPTCHA V3 solver and returns a token.
```php
$result = $solver->recaptcha([
'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
'url' => 'https://mysite.com/page/with/recaptcha',
'version' => 'v3',
]);
```### FunCaptcha
[API method description.](https://2captcha.com/2captcha-api#solving_funcaptcha_new)
FunCaptcha (Arkoselabs) solving method. Returns a token.
```php
$result = $solver->funcaptcha([
'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
'url' => 'https://mysite.com/page/with/funcaptcha',
]);
```### GeeTest
[API method description.](https://2captcha.com/2captcha-api#solving_geetest)
Method to solve GeeTest puzzle captcha. Returns a set of tokens as JSON.
```php
$result = $solver->geetest([
'gt' => 'f1ab2cdefa3456789012345b6c78d90e',
'challenge' => '12345678abc90123d45678ef90123a456b',
'url' => 'https://www.site.com/page/',
]);
```### GeeTest V4
[API method description.](https://2captcha.com/2captcha-api#geetest-v4)
Method to solve GeeTest V4 puzzle captcha. Returns a set of tokens as JSON.
```php
$result = $solver->geetest_v4([
'captchaId' => '72bf15796d0b69c43867452fea615052',
'url' => 'https://mysite.com/captcha.html',
]);
```### KeyCaptcha
[API method description.](https://2captcha.com/2captcha-api#solving_keycaptcha)
Token-based method to solve KeyCaptcha.
```php
$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/',
]);
```### Capy
[API method description.](https://2captcha.com/2captcha-api#solving_capy)
Token-based method to bypass Capy puzzle captcha.
```php
$result = $solver->capy([
'sitekey' => 'PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v',
'url' => 'http://mysite.com/',
'api_server' => 'https://jp.api.capy.me/',
]);
```### Grid
[API method description.](https://2captcha.com/2captcha-api#grid)
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.
```php
$result = $solver->grid('path/to/captcha.jpg');
```### Canvas
[API method description.](https://2captcha.com/2captcha-api#canvas)
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.
```php
$result = $solver->canvas('path/to/captcha.jpg');
```### ClickCaptcha
[API method description.](https://2captcha.com/2captcha-api#coordinates)
ClickCaptcha method returns coordinates of points on captcha image. Can be used if you need to click on particular points on the image.
```php
$result = $solver->coordinates('path/to/captcha.jpg');
```### Rotate
[API method description.](https://2captcha.com/2captcha-api#solving_rotatecaptcha)
This method can be used to solve a captcha that asks to rotate an object. Mostly used to bypass FunCaptcha. Returns the rotation angle.
```php
$result = $solver->rotate('path/to/captcha.jpg');
```### Audio
[API method description.](https://2captcha.com/2captcha-api#audio)
This method can be used to solve a audio captcha
```php
$result = $solver->audio('path/to/audio.mp3');
```### Yandex
Use this method to solve Yandex and obtain a token to bypass the protection.
```php
$result = $solver->yandex([
'sitekey' => 'Y5Lh0tiycconMJGsFd3EbbuNKSp1yaZESUOIHfeV',
'url' => 'https://rutube.ru',
]);
```### Lemin Cropped Captcha
[API method description.](https://2captcha.com/2captcha-api#lemin)
Use this method to solve Lemin and obtain a token to bypass the protection.
```php
$result = $solver->lemin([
'captchaId' => 'CROPPED_d3d4d56_73ca4008925b4f83a8bed59c2dd0df6d',
'apiServer' => 'api.leminnow.com',
'url' => 'https://www.site.com/page/',
]);
```### Cloudflare Turnstile
[API method description.](https://2captcha.com/2captcha-api#turnstile)
Use this method to solve Turnstile and obtain a token to bypass the protection.
```php
$result = $solver->turnstile([
'sitekey' => '0x4AAAAAAAChNiVJM_WtShFf',
'url' => 'https://ace.fusionist.io',
]);
```### Amazon WAF
[API method description.](https://2captcha.com/2captcha-api#amazon-waf)
Use this method to solve Amazon WAF and obtain a token to bypass the protection.
```php
$result = $solver->amazon_waf([
'sitekey' => 'AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AF5H1K/siwSLK7RfstKtN5bAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglg',
'url' => 'https://non-existent-example.execute-api.us-east-1.amazonaws.com',
'iv' => 'test_iv',
'context' => 'test_context'
]);
```### Tencent
[API method description.](https://2captcha.com/2captcha-api#tencent)
Use this method to bypass Tencent.
```php
$result = $solver->tencent([
'sitekey' => '123456789',
'url' => 'https://www.site.com/page/',
]);
```### MTCaptcha
[API method description.](https://2captcha.com/2captcha-api#mtcaptcha)
Use this method to bypass MTCaptcha.
```php
$result = $solver->mt_captcha([
'sitekey' => 'MTPublic-KzqLY1cKH',
'url' => 'https://2captcha.com/demo/mtcaptcha',
]);
```### Cutcaptcha
[API method description.](https://2captcha.com/2captcha-api#cutcaptcha)
Use this method to bypass Cutcaptcha.
```php
$result = $solver->cutcaptcha([
'misery_key' => 'a1488b66da00bf332a1488993a5443c79047e752',
'api_key' => 'SAb83IIB',
'url' => 'https://example.cc/foo/bar.html',
]);
```### Friendly Captcha
[API method description.](https://2captcha.com/2captcha-api#friendly-captcha)
Use this method to bypass Friendly Captcha.
```php
$result = $solver->friendly_captcha([
'sitekey' => '2FZFEVS1FZCGQ9',
'url' => 'https://example.com/',
]);
```### atbCAPTCHA
[API method description.](https://2captcha.com/2captcha-api#atb-captcha)
Use this method to bypass atbCAPTCHA.
```php
$result = $solver->atb_captcha([
'sitekey' => 'af23e041b22d000a11e22a230fa8991c',
'api_server' => 'https://cap.aisecurius.com',
'url' => 'https://example.com/',
]);
```### DataDome
[API method description.](https://2captcha.com/2captcha-api#datadome)
Use this method to bypass DataDome.
> [!IMPORTANT]
> To solve the DataDome captcha, you must use a proxy. It is recommended to use [residential proxies].```php
$result = $solver->datadome([
'captcha_url' => 'https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAA...P~XFrBVptk&t=fe&referer=https%3A%2F%2Fhexample.com&s=45239&e=c538be..c510a00ea',
'userAgent' => 'https://cap.aisecurius.com',
'url' => 'https://example.com/',
'proxy' => [
'type' => 'HTTPS',
'uri' => 'username:str0ngP@[email protected]:4321',
],
]);
```### CyberSiARA
[API method description.](https://2captcha.com/2captcha-api#cybersiara)
Use this method to bypass CyberSiARA.
```php
$result = $solver->cybersiara([
'master_url_id' => 'tpjOCKjjpdzv3d8Ub2E9COEWKt1vl1Mv',
'pageurl' => 'https://demo.mycybersiara.com/',
'userAgent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36',
]);
```## Other methods
### send / getResult
These methods can be used for manual captcha submission and answer polling.
```php
$id = $solver->send(['file' => 'path/to/captcha.jpg', ...]);sleep(20);
$code = $solver->getResult($id);
```
### balance[API method description.](https://2captcha.com/2captcha-api#additional-methods)
Use this method to get your account's balance
```php
$balance = $solver->balance();
```### report
[API method description.](https://2captcha.com/2captcha-api#complain)
Use this method to report good or bad captcha answer.
```php
$solver->report($id, true); // captcha solved correctly
$solver->report($id, false); // captcha solved incorrectly
```## Proxies
You can pass your proxy as an additional argument for methods: recaptcha, funcaptcha, geetest, geetest v4, keycaptcha, capy puzzle, lemin, turnstile, amazon waf and etc. The proxy will be forwarded to the API to solve the captcha.
We have our own proxies that we can offer you. [Buy residential proxies] for avoid restrictions and blocks. [Quick start].
Example solving reCAPTCHA V2 using proxy:
```php
$result = $solver->recaptcha([
'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
'url' => 'https://mysite.com/page/with/recaptcha',
'proxy' => [
'type' => 'HTTPS',
'uri' => 'login:password@IP_address:PORT',
],
]);
```## Error handling
If case of an error captch solver throws an exception. It's important to properly handle these cases. We recommend to use `try catch` to handle exceptions.
```php
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
}
```## Examples
Examples of solving all supported captcha types are located in the [examples] directory.
## Get in touch
## Join the team 👪
There are many ways to contribute, of which development is only one! Find your next job. Open positions: AI experts, scrapers, developers, technical support, and much more! 😍
## License
The code in this repository is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more details.
### Graphics and Trademarks
The graphics and trademarks included in this repository are not covered by the MIT License. Please contact support for permissions regarding the use of these materials.
[2Captcha]: https://2captcha.com/
[2captcha software catalog]: https://2captcha.com/software
[pingback settings]: https://2captcha.com/setting/pingback
[post options]: https://2captcha.com/2captcha-api#normal_post
[list of supported languages]: https://2captcha.com/2captcha-api#language
[examples directory]: /examples
[examples]: /examples
[PHP captcha solver]: https://2captcha.com/lang/php
[Buy residential proxies]: https://2captcha.com/proxy/residential-proxies
[residential proxies]: https://2captcha.com/proxy/residential-proxies
[Quick start]: https://2captcha.com/proxy?openAddTrafficModal=true