PHPackages                             wowe/recaptcha - 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. [Security](/categories/security)
4. /
5. wowe/recaptcha

ActiveLibrary[Security](/categories/security)

wowe/recaptcha
==============

Implementation of the Google reCAPTCHA API for PHP.

v1.0.0(11y ago)53782MITPHPPHP &gt;=5.4.0

Since Dec 7Pushed 9y ago1 watchersCompare

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

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

Recaptcha for PHP
=================

[](#recaptcha-for-php)

**Recaptcha for PHP** provides a full-featured PHP implementation of the [Google reCAPTCHA API](https://developers.google.com/recaptcha/) along with some helpful adapters for other popular packages. It specifically uses the "no CAPTCHA" version released in December 2014.

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Setup](#setup)
    - [Available Methods](#available-methods)
    - [Verification Error Codes](#verification-error-codes)
- [Adapters](#adapters)
    - [Twig](#twig)
    - [Slim Framework](#slim-framework)
- [Release Notes](#release-notes)
- [Version Compatibility](#version-compatibility)
- [License](#license)

Installation
------------

[](#installation)

**Via Composer**:
`composer require wowe/recaptcha:1.*`

Configuration
-------------

[](#configuration)

Only two values are required to use the package:

- `secret` The part of the API key pair used for authentication.
- `siteKey` The part of the API key pair which uniquely identifies your site.

Both of these values must be acquired from Google. Directions on how to do so may be found [here](https://developers.google.com/recaptcha/docs/start).

Usage
-----

[](#usage)

### Setup

[](#setup)

In order to use the package, create a new instance of the `Recaptcha` class, passing in the `secret` and `siteKey` values.

```
require 'vendor/autoload.php';
use \Wowe\Recaptcha\Recaptcha;

$recaptcha = new Recaptcha('secret', 'siteKey');
```

### Available Methods

[](#available-methods)

- `script($onload = null, $render = null, $hl = null, $attributes = array())`
    Generates a script tag based on the options.
    - $onload `string`: The name of the JavaScript function to be called on load.
    - $render `string`: When to render the widget ('explicit' or 'onload').
    - $hl `string`: The language to be used for the widget.
    - $attributes `array`: Additional attributes for the tag.
    - Returns `string`
- `widget($theme = null, $type = null, $callback = null, $attributes = array())`
    Generates a div tag for the widget based on the options.
    - $theme `string`: The color theme of the widget ('dark' or 'light').
    - $type `string`: The type of CAPTCHA to serve ('audio' or 'image').
    - $callback `string`: The name of the JavaScript callback function to be executed when the user submits a successful CAPTCHA response.
    - $attributes `array`: Additional attributes to be placed on the div.
    - Returns `string`
- `verify($response, $remoteIp = null)`
    Queries the Google API to determine if the CAPTCHA is valid.
    - $response `string`: The user response token.
    - $remoteIp `string`: The user's IP address.
    - Returns `boolean`
- `errors()`
    The list of errors from the last verification query.
    - Returns `array`

### Verification Error Codes

[](#verification-error-codes)

After calling `verify` you may call `errors` to get a list of any errors that may have been encountered. If any empty array is returned then there were no errors! If there are errors, they will most often be [error codes returned by the Google API](https://developers.google.com/recaptcha/docs/verify). In addition to those it may also return:

- `transfer-error`: An exception was encountered when attempting to connect to the API.
- `api-error`: A HTTP status code other than 200 was returned by the API.
- `response-error`: The format of the response returned by the API could not be read.

Adapters
--------

[](#adapters)

### Twig

[](#twig)

**[Website](http://twig.sensiolabs.org/) | [GitHub](https://github.com/twigphp/Twig)**
The `script` and `widget` methods can be exposed in Twig templates by adding an instance of the included `TwigExtension` class to the Twig environment. The `TwigExtension` instance must be initialized with an instance of the `Recaptcha` class. `script` is mapped to a function called `recaptchaScript` and `widget` is mapped to a function called `recaptchaWidget`. All arguments are the same as the definitions [above](#available-methods).

```
// index.php
require 'vendor/autoload.php';
use \Wowe\Recaptcha\Recaptcha;
use \Wowe\Recaptcha\Adapters\TwigExtension;

$recaptcha = new Recaptcha('secret', 'siteKey');
$loader = new Twig_Loader_Filesystem(__DIR__ . '/views');
$twig = new Twig_Environment($loader);
$twig->addExtension(new TwigExtension($recaptcha)));
echo $twig->render('index.html');

// views/index.html

        {{ recaptchaScript() }}

            {{ recaptchaWidget() }}

```

### Slim Framework

[](#slim-framework)

**[Website](http://www.slimframework.com/) | [GitHub](https://github.com/codeguy/Slim)**
The `Recaptcha` class can be registered as a singleton in the Slim container automatically by running the `SlimManager::register` method, which has three optional arguments:

- `register($registerViewExtension = false, $recaptcha = null, $appName = null)`
    Register a Recaptcha instance with the application container.
    - $registerViewExtension `boolean`: Whether or not to also register a view extension (if available).
    - $recaptcha `\Wowe\Recaptcha\Recaptcha`: The Recaptcha instance to bind to.
    - $appName `string`: The name of the application to register with.
    - Returns void

If you would like to instantiate the `Recaptcha` class yourself (in order to get the configuration values customly), you may do so and then just pass it to the `register` method. If no `Recaptcha` instance is passed then it will attempt to create one by getting the configuration values from the `Slim` app. In order to take advantage of this, set the configuration value `recaptcha` to an array with the `secret` and `siteKey` values as in the following example:

```
require 'vendor/autoload.php';
use \Slim\Slim;
use \Wowe\Recaptcha\Adapters\SlimManager;

$app = new Slim([
    'recaptcha' => [
        'secret' => 'secret',
        'siteKey' => 'siteKey'
    ]
]);

SlimManager::register();

$app->get('/', function () use ($app) {
    return $app->render('index.html');
});

$app->post('/', function () use ($app) {
    $recaptchaResponse = $app->request->post('g-recaptcha-response');
    var_dump($app->recaptcha->verify($recaptchaResponse), $app->recaptcha->errors());
});

$app->run();
```

If a value of `true` is passed as the `registerViewExtension` and a view engine is being used which has an extension available (eg. Twig), it will register the corresponding extension with the view engine.

Release Notes
-------------

[](#release-notes)

*Additional information can be found in the CHANGELOG.md file*

- v1.0.0 - Initial release

Version Compatibility
---------------------

[](#version-compatibility)

Recaptcha for PHP[Twig](#twig)[Slim Framework](#slim-framework)v1.xv1.xv2.xLicense
-------

[](#license)

The **Recaptcha for PHP** package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4179d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fd85655aa98bb76fc8280197bbdfdc7d28a8a9dfe972d6f0cee899b1290e41a2?d=identicon)[willrowe](/maintainers/willrowe)

---

Top Contributors

[![willrowe](https://avatars.githubusercontent.com/u/7152423?v=4)](https://github.com/willrowe "willrowe (10 commits)")

---

Tags

googlerecaptcha

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wowe-recaptcha/health.svg)

```
[![Health](https://phpackages.com/badges/wowe-recaptcha/health.svg)](https://phpackages.com/packages/wowe-recaptcha)
```

###  Alternatives

[phelium/recaptcha

reCAPTCHA v2 class

4389.4k](/packages/phelium-recaptcha)[cakephp-fr/recaptcha

To easily use Google Recaptcha (free CAPTCHA service that protect websites from spam and abuse) in CakePHP projects

1419.3k](/packages/cakephp-fr-recaptcha)[cake17/cakephp-recaptcha

\[DEPRECIATED\] Please use https://github.com/cakephp-fr/recaptcha/

1211.0k1](/packages/cake17-cakephp-recaptcha)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
