PHPackages                             maxsky/php-captcha - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. maxsky/php-captcha

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

maxsky/php-captcha
==================

v1.0.0(1y ago)016MITPHPPHP ^7.2.5|^8.0

Since Feb 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/maxsky/php-captcha)[ Packagist](https://packagist.org/packages/maxsky/php-captcha)[ RSS](/packages/maxsky-php-captcha/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

php-captcha
===========

[](#php-captcha)

Support Google reCaptcha, Cloudflare Turnstile, hCaptcha, Vaptcha validate.

Install
-------

[](#install)

```
composer require maxsky/php-captcha
```

Simple usage
------------

[](#simple-usage)

### Google Recaptcha

[](#google-recaptcha)

```
$token = 'Recaptcha_Response_Value_From_Request'; // g-recaptcha-response
// $clientIp = 'Request_Client_IP'; // optional

$params = [
    'secret' => 'Your_Recaptcha_Verify_Key',
];

try {
    $result = CaptchaService::init($params)->recaptcha($token)->verify();
    // $result = CaptchaService::init($params)->recaptcha($token, $clientIp)->verify();
} catch (\Exception $e) {
    // Request or Response error
    // \MaxSky\Captcha\Exceptions\CaptchaRequestException
    // \MaxSky\Captcha\Exceptions\CaptchaResponseException
}

var_dump($result);
```

Value example:

```
array (size=4)
  'success' => boolean true
  'challenge_ts' => string '2025-02-17T08:57:28Z' (length=20)
  'hostname' => string '127.0.0.1' (length=9)
  'score' => float 0.9
```

### Cloudflare Turnstile

[](#cloudflare-turnstile)

```
$token = 'Turnstile_Response_Value_From_Request'; // cf-turnstile-response
$clientIpOptional = 'Request_Client_IP'; // optional

$params = [
    'secret' => 'Your_Turnstile_Verify_Key'
];

$result = CaptchaService::init($params)->turnstile($token, $clientIpOptional)->verify();

var_dump($result);
```

Value example:

```
array (size=7)
  'success' => boolean true
  'error-codes' =>
    array (size=0)
      empty
  'challenge_ts' => string '2025-02-17T08:59:11.241Z' (length=24)
  'hostname' => string '127.0.0.1' (length=9)
  'action' => string '' (length=0)
  'cdata' => string '' (length=0)
  'metadata' =>
    array (size=1)
      'interactive' => boolean false
```

### Hcaptcha

[](#hcaptcha)

```
// $params & $token same as recaptcha & turnstile
$result = CaptchaService::init($params)->hcaptcha($token, $clientIpOptional)->verify();

var_dump($result);
```

Value example:

```
array (size=3)
  'success' => boolean true
  'challenge_ts' => string '2025-02-17T09:03:43.000000Z' (length=27)
  'hostname' => string '127.0.0.1' (length=9)
```

### Vaptcha

[](#vaptcha)

```
$token = 'Vaptcha_Response_Token_From_Request'; // vaptcha_token
$server = 'Vaptcha_Response_Server_From_Request'; // vaptcha_server
$clientIp = 'Request_Client_IP'; // Required

$params = [
    'id' => 'Your_Vaptcha_VID',
    'secretkey' => 'Your_Vaptcha_Key',
    'scene' => 0, // scene ID, default 0
    'server' => $server
];

$result = CaptchaService::init($params)->vaptcha($token, $clientIp)->verify();

var_dump($result);
```

Value example:

```
array (size=3)
  'msg' => string 'success' (length=7)
  'success' => int 1
  'score' => int 90
```

Compatible usage
----------------

[](#compatible-usage)

**Example by Laravel Framework**

### 1. Create config file

[](#1-create-config-file)

`config/captcha.php` file

```
