PHP client library for reCAPTCHA, a free service to protect your website from spam and abuse.

Overview

reCAPTCHA PHP client library

Build Status Coverage Status Latest Stable Version Total Downloads

reCAPTCHA is a free CAPTCHA service that protects websites from spam and abuse. This is a PHP library that wraps up the server-side verification step required to process responses from the reCAPTCHA service. This client supports both v2 and v3.

Installation

Composer (recommended)

Use Composer to install this library from Packagist: google/recaptcha

Run the following command from your project directory to add the dependency:

composer require google/recaptcha "^1.2"

Alternatively, add the dependency directly to your composer.json file:

"require": {
    "google/recaptcha": "^1.2"
}

Direct download

Download the ZIP file and extract into your project. An autoloader script is provided in src/autoload.php which you can require into your script. For example:

require_once '/path/to/recaptcha/src/autoload.php';
$recaptcha = new \ReCaptcha\ReCaptcha($secret);

The classes in the project are structured according to the PSR-4 standard, so you can also use your own autoloader or require the needed files directly in your code.

Usage

First obtain the appropriate keys for the type of reCAPTCHA you wish to integrate for v2 at https://www.google.com/recaptcha/admin or v3 at https://g.co/recaptcha/v3.

Then follow the integration guide on the developer site to add the reCAPTCHA functionality into your frontend.

This library comes in when you need to verify the user's response. On the PHP side you need the response from the reCAPTCHA service and secret key from your credentials. Instantiate the ReCaptcha class with your secret key, specify any additional validation rules, and then call verify() with the reCAPTCHA response and user's IP address. For example:

<?php
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->setExpectedHostname('recaptcha-demo.appspot.com')
                  ->verify($gRecaptchaResponse, $remoteIp);
if ($resp->isSuccess()) {
    // Verified!
} else {
    $errors = $resp->getErrorCodes();
}

The following methods are available:

  • setExpectedHostname($hostname): ensures the hostname matches. You must do this if you have disabled "Domain/Package Name Validation" for your credentials.
  • setExpectedApkPackageName($apkPackageName): if you're verifying a response from an Android app. Again, you must do this if you have disabled "Domain/Package Name Validation" for your credentials.
  • setExpectedAction($action): ensures the action matches for the v3 API.
  • setScoreThreshold($threshold): set a score threshold for responses from the v3 API
  • setChallengeTimeout($timeoutSeconds): set a timeout between the user passing the reCAPTCHA and your server processing it.

Each of the set*() methods return the ReCaptcha instance so you can chain them together. For example:

<?php
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->setExpectedHostname('recaptcha-demo.appspot.com')
                  ->setExpectedAction('homepage')
                  ->setScoreThreshold(0.5)
                  ->verify($gRecaptchaResponse, $remoteIp);

if ($resp->isSuccess()) {
    // Verified!
} else {
    $errors = $resp->getErrorCodes();
}

You can find the constants for the libraries error codes in the ReCaptcha class constants, e.g. ReCaptcha::E_HOSTNAME_MISMATCH

For more details on usage and structure, see ARCHITECTURE.

Examples

You can see examples of each reCAPTCHA type in examples/. You can run the examples locally by using the Composer script:

composer run-script serve-examples

This makes use of the in-built PHP dev server to host the examples at http://localhost:8080/

These are also hosted on Google AppEngine Flexible environment at https://recaptcha-demo.appspot.com/. This is configured by app.yaml which you can also use to deploy to your own AppEngine project.

Contributing

No one ever has enough engineers, so we're very happy to accept contributions via Pull Requests. For details, see CONTRIBUTING

Comments
  • FUCK RECAPTCHA

    FUCK RECAPTCHA

    This is honestly the WORST fucking thing imaginable. According to it I am robot most of the fucking time. Not only it uses terrible images (how the fuck do I determine what is a storefront when I see kanji crap etc) it fails almost all the time, it won't detect corner cases like (like does fucking pedestrian traffic light apply? Do you select tile if just part of fucking thing is in the view?). It's absolutely fucking retarded. I would rather have fucking bots posting spam everywhere but this shit. Delete this google and start again.

    service discussion 
    opened by Enerccio 81
  • ReCaptcha is not really responsive.

    ReCaptcha is not really responsive.

    As I have the problem now, the recaptcha has a fixed size and should be responsive. Here is a bug ticket from februrary: https://code.google.com/p/recaptcha/issues/detail?id=215

    widget 
    opened by Chris2011 79
  • ReCaptcha on iOS scrolling issue

    ReCaptcha on iOS scrolling issue

    I'm having the following issue with ReCaptcha on an iPhone SE (iOS 10.1) Safari and Chrome:

    The "I'm not a robot" option renders fine, but when you check the box and the image challenge appears, the scroll is forced to the bottom of the page (the .focus() seems to jump to the div appended to the body) which means the challenge isn't in view and users have to scroll up.

    Does anyone else have this issue? Any ideas what may be happening or how I can fix?

    widget 
    opened by NathJoyce 56
  • ReCaptcha extremly slow fading

    ReCaptcha extremly slow fading

    hi there,

    since some months (as I remember it is maybe July) the recaptcha fades aout and reappears veeeery slow. And if I solved it, it means that I solved it wrong. I dont know how many forms I had to re-fill-out because of that. That's the reason why I open this issue.

    I found out, that this mostly happens in Google's Chrome itself. When I try to solve the ReCaptcha in Safari, it works blazingly fast. I deactivated every Extension but that wont solve my slow Recaptchas.

    Any ideas how to get rid of that annoying and disappointing issue? (Version 69.0.3497.100 (Offizieller Build) (64-Bit) on a Mac (10.13.6 (17G65))

    many thanks in advance

    (you can see it here in action: https://drive.google.com/file/d/18EzfmS-synbS6YKEVmV5Wf2yIGBVh1Ee/view?usp=sharing )

    service discussion 
    opened by exocode 44
  • Recaptcha is so buggy as hell

    Recaptcha is so buggy as hell

    Honestly Recpatcha is so bad that we should use the traditional captcha codes.

    Before recaptcha used to be great most of the times I used to check on the box and it was fine. Now everytime i click ont he check box I am forced to "Find all the cars" for example. WHy do you give such hard to see images with cars that are placed so far back to make it nearly impossible to see for example? Why cant you just have simple non cartoon images. Also it keeps saying that "Your computer or network may be sending automated queries. To protect our users, we can't process your request right now. For more details visit our help page" So now everytime I want to do something, I have to deal with this crap. Websites are so unusable because of this. Please fix it and make it what it used to be like.

    opened by Raj2032 39
  • Create proxy handlers for China.

    Create proxy handlers for China.

    I don't know where to start this discussion so I will start it here.

    China has blocked recaptcha. The service is awesome, so I'd like to attempt to workaround this.

    My idea would be this.

    1. All network requests are proxies through a server handler. "http://mydomain.com/recpatcha/http://google.com/recpatcha/image.jpeg" and "http://mydomain.com/recpatcha/http://google.com/recpatcha/script.js" would be proxied and served as if the content came from "mydomain.com".
    2. There may need to by some "live" modification of the scripts and styles returned from the proxy so that all urls and domains have the "http://mydomain.com/recaptcha" preappended to them.

    What do you guys think? I haven't tried it yet, but does anyone know if there would be any hangups with this approach?

    question 
    opened by pauldotknopf 37
  • Recaptcha audio challenge language

    Recaptcha audio challenge language

    I can't find any documentation on whether it is possible or not to get the audio challenge in a specific language. I've managed to get the widget in french but the audio challenge still is in english. Is there any way I can get a french audio challenge ?

    widget 
    opened by PierreCavalet 30
  • Recaptcha should support strict CSP style-src rules.

    Recaptcha should support strict CSP style-src rules.

    The documentation now advice developers to enable style-src='unsafe-inline'.

    Should not Recaptcha give an alternative that does not require developers to lower their sites security?

    widget 
    opened by hmosvoll 26
  • Recaptcha is requesting recaptcha__en.js file multiple times

    Recaptcha is requesting recaptcha__en.js file multiple times

    Hi there,

    I was having this problem with one of my projects and to try to figure out what was wrong I decided to run the example code from recaptcha docs.

    Even with this example code the page is still requesting the file multiple times.

    Here is a jsFiddle with the example code: https://jsfiddle.net/7h7rnqbn/

    Just open the network tab and see the file requests.

    widget 
    opened by Rueff19 24
  • Is Mailhide no longer supported?

    Is Mailhide no longer supported?

    I noticed today that the v1 API for recpatcha had been turned off as of March 31 2018.

    Now my mailhide links show a warning:

    screen shot 2018-04-03 at 5 57 20 pm

    But there's no clear way to upgrade to the v2 API. The mailhide home page still generates links that appear to use the old API.

    Has mailhide been abandoned?

    question service discussion 
    opened by hodgesmr 21
  • callback method not firing in grecaptcha.render()

    callback method not firing in grecaptcha.render()

    I am trying to have my callback fire once recaptacha i loaded however it won't load the callback.

    Taken from https://developers.google.com/recaptcha/docs/display#example

            grecaptcha.render('example3', {
              'sitekey' : 'your_site_key',
              'callback' : verifyCallback,
              'theme' : 'dark'
            });
    

    In my example I am doing:

                grecaptcha.render('recaptcha', {
                    'sitekey': config.recaptcha.id,
                    'callback': function(){
                          console.info('something'); 
                     }
                });
    
    

    The callback function will never execute. reCacptcha will however load in the page.

    Latest version of Chrome.

    widget 
    opened by hutber 18
  • Add needed attribute for ReCaptcha to work with PHP8.2

    Add needed attribute for ReCaptcha to work with PHP8.2

    When switching to PHP8.2 I have the following issue with ReCaptcha/ReCaptcha

    Capture d’écran 2022-12-28 à 15 34 19

    It's because this class is full of dynamic properties, which is not accepted by PHP8.2 without this attribute.

    opened by MarvinCourcier 1
  • Thousands of

    Thousands of "Cannot read property get of undefined" errors

    Issue description At work we're seeing tons of errors reported through Sentry that say "TypeError: null is not an object (evaluating 'w.style')"

    Environment

    • OS name and version: Windows and Mac
    • PHP version: N/A
    • Web server name and version: Which web server?
    • google/recaptcha version: Latest as served by https://www.recaptcha.net/recaptcha/api.js
    • Browser name, version and ratio:

    LINE 12.21.0 | 0.1359% Chrome 108.0.0 | 0.1359% Facebook 339.0.0 | 0.1359% LINE 12.1.0 | 0.1359% Mobile Safari 15.5 | 0.2717% LINE 12.20.0 | 0.2717% Instagram 262.0.0 | 0.1359% Safari 15.6 | 0.1359% LINE 11.18.0 | 0.1359% LINE 12.8.0 | 0.1359% LINE 12.6.0 | 0.1359% Mobile Safari 14.0.2 | 0.1359% Mobile Safari 14.0.3 | 0.1359% LINE 11.19.1 | 0.1359% LINE 12.3.0 | 0.4076% LINE 12.7.0 | 0.1359% Chrome Mobile iOS 108.0.5359 | 0.2717% LINE 10.17.0 | 0.1359% LINE 12.8.1 | 0.4076% LINE 11.3.0 | 0.1359% LINE 12.12.0 | 0.6793% LINE 11.10.0 | 0.1359% Mobile Safari 15.6.3 | 0.1359% LINE 12.11.1 | 0.6793% Instagram 259.0.0 | 0.2717% LINE 12.4.0 | 1.0870% Mobile Safari 15.6 | 0.4076% LINE 12.9.0 | 0.4076% LINE 12.2.1 | 0.2717% Facebook 390.0.0 | 0.1359% LINE 12.17.1 | 2.5815% Mobile Safari 15.4 | 0.5435% LINE 12.20.2 | 1.2228% LINE 11.19.2 | 0.1359% LINE 12.10.0 | 0.2717% LINE 12.14.1 | 0.9511% LINE 12.21.1 | 1.4946% Mobile Safari 16.0 | 4.2120% Mobile Safari 15.6.1 | 0.8152% Instagram 261.0.0 | 0.2717% LINE 12.15.1 | 0.8152% Instagram 263.1.0 | 2.0380% LINE 12.13.0 | 1.3587% Mobile Safari 16.1 | 6.5217% LINE 12.16.0 | 1.6304% LINE 12.18.0 | 2.8533% LINE 12.19.0 | 7.3370% Mobile Safari 16.2 | 1.4946% LINE 12.20.1 | 55.5707%

    Reproducing the issue All error messages happen after POST to https://identitytoolkit.googleapis.com/v1/accounts:sendVerificationCode?key=xxxxxxxxx then get the following errors:

    TypeError: null is not an object (evaluating 'w.style')
      at ? (/recaptcha/releases/5qcenVbrhOy8zihcc2aHOWD4/recaptcha__zh_tw.js:445:335)
      at ? (/recaptcha/releases/5qcenVbrhOy8zihcc2aHOWD4/recaptcha__zh_tw.js:167:202)
      at ? ([native code])
      at sentryWrapped(../helpers.ts:87:17)
    

    User steps Unfortunately I cannot provide this information. I work for a private SAAS company.

    opened by sp0033212000 0
  • Focus Indicator on Captcha check box is not visible in High Contrast Black/White themes

    Focus Indicator on Captcha check box is not visible in High Contrast Black/White themes

    Issue description Focus Indicator on Captcha check box is not visible in High Contrast Black and White themes

    Environment

    • OS name and version: Windows 10 & 11
    • google/recaptcha version: Google recatcha component from Kentico version 11
    • Browser name and version: Edge & Chrome

    Reproducing the issue Navigate to High Contrast theme settings and select Black/White in Windows 10 or Desert or Aquatic in high OS versions. And then access the below mentioned URL from Edge or Chrome Browser and navigate onto the check box using tab key

    URL: https://www.google.com/recaptcha/api2/demo)

    opened by v-vasud 0
  • Uncaught (in promise) TypeError: Cannot read properties of undefined ('key') at Array.<anonymous> (recaptcha__en.js:143:196)

    Uncaught (in promise) TypeError: Cannot read properties of undefined ('key') at Array. (recaptcha__en.js:143:196)

    Only calling executeRecaptcha on Submit form, Get this error sometime on page refresh OR page load. Very annoying for UX.

    How do I solve this issue??

    Framework: Next.js

    Console stack trace:

    at Array.<anonymous> (recaptcha__en.js:143:196)
        at recaptcha__en.js:289:485
        at eval (react-google-recaptcha-v3.esm.js?e46a:15:4603)
        at _callee$ (search-input.component.tsx?f48d:76:27)
        at tryCatch (runtime.js?ecd4:45:16)
        at Generator.invoke [as _invoke] (runtime.js?ecd4:274:1)
        at prototype.<computed> [as next] (runtime.js?ecd4:97:1)
        at asyncGeneratorStep (asyncToGenerator.js?8d4f:3:1)
        at _next (asyncToGenerator.js?8d4f:25:1)
        at eval (asyncToGenerator.js?8d4f:32:1)
        at new Promise (<anonymous>)
        at eval (asyncToGenerator.js?8d4f:21:1)
        at eval (search-input.component.tsx?f48d:116:5)
        at commitHookEffectListMount (react-dom.development.js?ac89:23049:1)
        at commitPassiveMountOnFiber (react-dom.development.js?ac89:24816:1)
        at commitPassiveMountEffects_complete (react-dom.development.js?ac89:24781:1)
        at commitPassiveMountEffects_begin (react-dom.development.js?ac89:24768:1)
        at commitPassiveMountEffects (react-dom.development.js?ac89:24756:1)
        at flushPassiveEffectsImpl (react-dom.development.js?ac89:26990:1)
        at flushPassiveEffects (react-dom.development.js?ac89:26935:1)
        at eval (react-dom.development.js?ac89:26725:1)
        at workLoop (scheduler.development.js?bcd2:266:1)
        at flushWork (scheduler.development.js?bcd2:239:1)
        at MessagePort.performWorkUntilDeadline (scheduler.development.js?bcd2:533:1)
    (anonymous) @ recaptcha__en.js:143
    (anonymous) @ recaptcha__en.js:289
    eval @ webpack-internal:///…aptcha-v3.esm.js:27
    _callee$ @ webpack-internal:///…t.component.tsx:157
    tryCatch @ webpack-internal:///…ntime/runtime.js:45
    invoke @ webpack-internal:///…time/runtime.js:274
    prototype.<computed> @ webpack-internal:///…ntime/runtime.js:97
    asyncGeneratorStep @ webpack-internal:///…yncToGenerator.js:7
    _next @ webpack-internal:///…ncToGenerator.js:29
    eval @ webpack-internal:///…ncToGenerator.js:36
    eval @ webpack-internal:///…ncToGenerator.js:25
    eval @ webpack-internal:///…t.component.tsx:231
    commitHookEffectListMount @ webpack-internal:///…evelopment.js:23044
    commitPassiveMountOnFiber @ webpack-internal:///…evelopment.js:24811
    commitPassiveMountEffects_complete @ webpack-internal:///…evelopment.js:24776
    commitPassiveMountEffects_begin @ webpack-internal:///…evelopment.js:24763
    commitPassiveMountEffects @ webpack-internal:///…evelopment.js:24751
    flushPassiveEffectsImpl @ webpack-internal:///…evelopment.js:26985
    flushPassiveEffects @ webpack-internal:///…evelopment.js:26930
    eval @ webpack-internal:///…evelopment.js:26720
    workLoop @ webpack-internal:///….development.js:266
    flushWork @ webpack-internal:///….development.js:239
    performWorkUntilDeadline @ webpack-internal:///….development.js:533
    
    opened by temrb 0
  • Uncaught (in promise) Timeout When user clicks on the check box of the recaptcha.

    Uncaught (in promise) Timeout When user clicks on the check box of the recaptcha.

    I'm adding like this to my cshtml page(It's a asp .net Core web application)

    image

    When page loaded for the first time. When user click on the check box, It's showing the loader symbol continuously like below

    image

    When we refresh the page it work fine. But at the first time we're facing this issue.

    Is there any solution for it ?

    In the console I'm seeing the below error

    image

    opened by samthrusha123 0
Owner
Google
Google ❤️ Open Source
Google
Hcaptcha & Google ReCaptcha Solution for Laravel Framework

Laravel Captcha is a wrapper around HCaptcha & Google Recaptcha. It provides very easy-to-use Facade, Validation Rule, and blade directives.

Rahul Dey 47 Oct 27, 2022
A laravel service provider for the netsuite-php library service

netsuite-laravel A PHP supplemental package to the ryanwinchester/netsuite-php package to add the NetSuite service client to the service container of

NetsuitePHP 6 Nov 9, 2022
an opensourced roblox group finder writen in python 100% free and virus-free

Roblox-Group-Finder an opensourced roblox group finder writen in python 100% free and virus-free note : if you don't want install python or just use w

mollomm1 1 Nov 11, 2021
Shared code for the MaxMind Web Service PHP client APIs

Common Code for MaxMind Web Service Clients This is not intended for direct use by third parties. Rather, it is for shared code between MaxMind's vari

MaxMind 264 Jan 3, 2023
My aim is to make a complete website that should have all the essential parts a website should have.

Gaming-Ninja I aim to make a complete website that should have all the essential parts a website should have. https://gamingninja-3399.000webhostapp.c

Anand Jaiswar 3 Nov 23, 2022
Load Laravel service providers based on your application's environment.

Laravel EnvProviders A more finetuned way of managing your service providers in Laravel. This package allows you to configure the environment certain

Sven Luijten 79 Dec 29, 2022
A bring-your-own-email-first newsletter service. ✨

Typewrite Typewrite a hosted bring-your-own-email newsletter service for people who need a simplistic and privacy-first newsletter service. The core a

Ryan Chandler 3 Dec 2, 2021
Laravel 4.* and 5.* service providers to handle PHP errors, dump variables, execute PHP code remotely in Google Chrome

Laravel 4.* service provider for PHP Console See https://github.com/barbushin/php-console-laravel/releases/tag/1.2.1 Use "php-console/laravel-service-

Sergey 73 Jun 1, 2022
Live Helper Chat - live support for your website. Featuring web and mobile apps, Voice & Video & ScreenShare. Supports Telegram, Twilio (whatsapp), Facebook messenger including building a bot.

Live helper chat It's an open-source powered application, which brings simplicity and usability in one place. With live helper chat you can bring live

Live Helper Chat 1.7k Dec 29, 2022
Laravel Abdal Detector - Find info about IP , OS and web browser from your client

Laravel Abdal Detector - Find info about IP , OS and web browser from your client

 Abdal Security Group 1 Mar 24, 2022
An issue tracking tool based on laravel+reactjs for small and medium-sized enterprises, open-source and free, similar to Jira.

ActionView English | 中文 An issue tracking tool based on php laravel-framework in back-end and reactjs+redux in front-end, it's similar to Jira. You co

null 1.7k Dec 23, 2022
Generate and autoload custom Helpers, Builder Scope, Service class, Trait

laravel-make-extender Generate and autoload custom helpers, It can generate multilevel helpers in the context of the directory. Generate Service class

Limewell 30 Dec 24, 2022
MediaDB is a web-based media streaming service written in Laravel and Vue.

MediaDB (API) MediaDB is a web-based media streaming service written in Laravel and Vue. The nginx-vod-module is used for on-the-fly repackaging of MP

François M. 53 Sep 3, 2022
A simple package to manage the creation of a structure composed of the service and repository layers in a Laravel application

Chapolim Este projeto tem como objetivo fornecer alguns comandos adicionais à interface de linha de comando do Laravel, o Artisan, para manipular a es

Eliezer Alves 51 Dec 11, 2022
Email validation service in PHP

Email validation service Email validation service in PHP using Laravel 8. Validation features Domain Regular Expression Smtp Txt records Installing de

Pedro 1 Oct 30, 2021
Laravel package that converts your application into a static HTML website

phpReel Static Laravel Package phpReel Static is a simple Laravel Package created and used by phpReel that converts your Laravel application to a stat

phpReel 16 Jul 7, 2022
This Laravel 8 package makes it possible for you to set your website in "Under Construction" mode.

Laravel Under Construction This Laravel package makes it possible to set your website in "Under Construction" mode. Only users with the correct 4 digi

Lars Janssen 571 Dec 18, 2022
A REST client inside your Laravel app

Laravel Compass is an elegant REST assistant for the Laravel framework that you can use to test API calls and create API documentation. it provides automatically endpoints for GET, POST, PUT/PATCH, DELETE, various auth mechanisms, and other utility endpoints based on Laravel routes in your project.

David H. Sianturi 1.2k Dec 31, 2022
Dashboard to view your http client requests in laravel application

Laravel Blanket is a package with wraps laravel http client requests and provide logs for request and response, also give option to retry any request from dashboard and more...

Ahmed waleed 215 Dec 29, 2022