google/recaptcha
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Google's reCAPTCHA is an invaluable tool in today's internet environment, offering a free service that strongly defends web platforms against spam and abuse. Its function revolves primarily around delivering servers-side verification required for processing responses from the reCAPTCHA service. The reCAPTCHA PHP client library is highly versatile, providing support to both version 2 and 3 of the reCAPTCHA service. Combining advanced technology with a user-friendly interface, it presents an efficient way to verify user interactions on your website, effectively separating humans from bots.
Implementing Google's reCAPTCHA library in PHP is a relatively straightforward process. First, you should install the library to your project using Composer, which is the recommended method. By running the command composer require google/recaptcha "^1.3"
in your project directory, you can easily add the necessary dependency.
Once the library is added, it's time to integrate it into your code. Get the necessary keys for v2 or v3 reCAPTCHA at the Google reCAPTCHA admin site and follow the integration guide. When you need to verify a user's response, you instantiate the ReCaptcha
class with your secret key, specify potential validation rules, and call verify()
with the reCAPTCHA response. The user's IP address is also required. This is how it is done:
<?php
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->setExpectedHostname('recaptcha-demo.appspot.com')
->verify($gRecaptchaResponse, $remoteIp);
if ($resp->isSuccess()) {
// Verified!
} else {
$errors = $resp->getErrorCodes();
}
Remember, the setExpectedHostname()
method is crucial when "Domain/Package Name Validation" for your credentials is disabled. Additional available functionalities include score threshold setting for v3 API responses, selection of a timeout interval, among others.
For a comprehensive understanding of google/recaptcha and its vibrant functionalities, the reCAPTCHA PHP client library README is the authoritative information repository. In-depth details about the architecture of this library, as well as guidelines for contributing to its development, are also available. For a practical perspective, the document also provides access to examples. Furthermore, developers are welcome to explore the reCAPTCHA integration guide on the Google Developers site to learn how to integrate reCAPTCHA functionalities into the front end of a web application.