maatify/hcaptcha

Unofficial HCaptcha for PHP it's library for maatify.dev HCaptcha handler, known by our team

1.0.0005 2024-08-10 11:13 UTC

This package is auto-updated.

Last update: 2024-11-14 02:00:21 UTC


README

Current version Packagist PHP Version Support Monthly Downloads Total Downloads Stars

Installation

composer require maatify/hcaptcha

Usage

<?php
/**
 * Created by Maatify.dev
 * User: Maatify.dev
 * Date: 2024-08-07
 * Time: 1:10 PM
 * https://www.Maatify.dev
 */
 
use Maatify\HCaptcha\HCaptchaPublisherProValidation;

require 'vendor/autoload.php';

$secret_key = '0x0000000000000000000000000000000000000000';

$hCaptcha = HCaptchaPublisherProValidation::getInstance($secret_key);

// ===== get result in array format
$result = $hCaptcha->getResponse();

// ====== get bool of validation 
$result = $hCaptcha->isSuccess();

// ====== using maatify json on error response with json code with die and if success there is no error
$hCaptcha->jsonErrors();

examples

getResponse();

Success Example
Array
(
  [success] => 1
  [challenge_ts] => 2024-08-07T10:09:36.000000Z
  [hostname] => localhost
  [credit] =>
)
Error Example
Array
  (
      [success] =>
      [error-codes] => Array
          (
              [0] => missing-input-response
              [1] => missing-input-secret
          )
  )

isSuccess();

return true || false

jsonErrors();

Error Example

Header 400

Body:

  • on validation error
{
 "success": false,
 "response": 40002,
 "var": "captcha",
 "description": {
   "success": false,
   "error-codes": [
     "invalid-input-secret"
   ],
   "messages": []
 },
 "more_info": "invalid-input-secret",
 "error_details": "test:72"
}
{
 "success": false,
 "response": 40002,
 "var": "captcha",
 "description": {
   "success": false,
   "error-codes": [
     "timeout-or-duplicate"
   ],
   "messages": []
 },
 "more_info": "timeout-or-duplicate",
 "error_details": "test:72"
}
  • on missing or empty $_POST['h-captcha-response']
  {
      "success": false,
      "response": 1000,
      "var": "h-captcha-response",
      "description": "MISSING h-captcha-response",
      "more_info": "",
      "error_details": ""
  }

Create From in HTML Code

<form action="process.php" method="POST">
    <form method="POST">
        <!-- Your other form fields -->
        <div class="h-captcha" data-sitekey="__YOUR_SITE_KEY__" data-theme="dark" data-hl="ar"></div>
        <input type="submit" value="Submit">
    </form>

    <script src="https://js.hcaptcha.com/1/api.js" async defer></script>