reCAPTCHA library

v0.3.1 2017-04-05 13:26 UTC

This package is auto-updated.

Last update: 2024-05-05 18:04:18 UTC


This is a package to implement reCAPTCHA (


Require this package with composer:

composer require fruitcakestudio/recaptcha


You can create a new instance by passing the SiteKey and Secret from your API. You can get that at

use FruitcakeStudio\ReCaptcha\ReCaptcha;

$captcha = new ReCaptcha($siteKey, $secret, 'en');

Widget usage

To show the reCAPTCHA on a form, use the class to render the script tag and the widget.

<?php echo $captcha->getScript() ?>
<form method="POST">
    <?php echo $captcha->getWidget() ?>
    <input type="submit" value="Submit" />

See for more options.

Verifying a response

After the post, use the class to verify the response. You get true or false back. You can access the error codes with $captcha->getErrors() as array, or get a readable message:

if ($captcha->verify($_POST["g-recaptcha-response"], $_SERVER["REMOTE_ADDR"])) {
    echo "OK!";
} else {
    echo "FAILED! " . $captcha->getErrorMessage();

Note: An error message is not always present.

You can also let the class discover the POST response and remote IP by using verifyGlobals();

if ($captcha->verifyGlobals()) {
    echo "OK!";

If you are using Symfony HttpFoundation, you can use the Request object instead of the globals.

if ($captcha->verifyRequest($request)) {
    echo "OK!";

// Or by setting the request before
if ($captcha->verifyRequest()) {
    echo "OK!";

See the docs on

Laravel integration

Since 0.3.x, Laravel integration is supported with a standalone package:

The classes are the same, only the configuration package name is 'laravel-recaptcha' instead of 'recaptcha'.