freddiegar/g-recaptcha

Library agnostic to connect/valid Google Recaptcha in PHP projects

1.0.0 2017-12-20 15:06 UTC

This package is auto-updated.

Last update: 2024-06-06 08:32:20 UTC


README

Valid g-ReCaptcha 2.0 in your back-end project

You can view details to back-end integration in docs

Use example

  $params = [
       'secret' => 'YOUR_SECRET_FROM_RECAPTCHA',
       'reCaptcha' => $_POST['g-recaptcha-response']
       // Optional parameters
       'userAgent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36'
       'ipAddress' => '127.0.0.1',
  ];

  try {
      $captcha = new ReCaptcha2($params);
      $request = $captcha->request();

      if ($request->isValid()) {
          // Dont is bot, ready!
      } else {
          $error = $captcha->getErrors();
      }
  } catch (Exception $exception) {
      $error = $exception->getMessage();
  }

Side Client

You can view details to front-end integration in docs