Download the PHP package karser/karser-recaptcha3-bundle without Composer

On this page you can find all versions of the php package karser/karser-recaptcha3-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package karser-recaptcha3-bundle

KarserRecaptcha3Bundle

Build Status Scrutinizer Code Quality Code Coverage Total Downloads

reCAPTCHA v3 returns a score for each request without user friction. The score is based on interactions with your site (1.0 is very likely a good interaction, 0.0 is very likely a bot) and enables you to take an appropriate action for your site. Register reCAPTCHA v3 keys here.

image

Installation

With composer, require:

composer require karser/karser-recaptcha3-bundle

You can quickly configure this bundle by using symfony/flex:

Configuration without symfony/flex:

1. Register the bundle

Symfony 4/5/6/7 Version :
Register bundle into config/bundles.php:

Symfony 3 Version:
Register bundle into app/AppKernel.php:

2. Add configuration files

Add your site key and secret to your .env file:

Usage

How to integrate re-captcha in Symfony form:

Notes:

How to use reCAPTCHA globally (meaning even in China):

Use 'www.recaptcha.net' host in your code when 'www.google.com' is not accessible.

How can I set the captcha language for different locales?

You can control the language in the small widget displayed by setting the locale in the options above.

To change the error messages, you should install the Symfony Translation component.

Then replace the validation text with the translation keys for the message and messageMissingValue options: ` Add English, Spanish, or any other translation:

How to get the ReCaptcha score:

Inject the Recaptcha3Validator and call getLastResponse()->getScore() after the form was submitted:

How to integrate re-captcha in API method:

The idea is to require the frontend to submit the captcha token, so it will be validated on server side.

First you need to add the captcha field to your transport entity:

And to add the validation constraint:

On frontend part you need to submit the captcha token along with email. You can obtain the captcha token either on page load or on form submit.

How to show errors from the captcha's response

Just add the {{ errorCodes }} variable to the message template:

How to deal with functional and e2e testing:

Recaptcha won't allow you to test your app efficiently unless you disable it for the environment you are testing against.

How to set the threshold from PHP dynamically rather from the .yaml config or .env?

You should inject @karser_recaptcha3.google.recaptcha in your service and call setScoreThreshold method.

How to resolve IP propertly when behind Cloudflare:

From the Cloudflare docs: To provide the client (visitor) IP address for every request to the origin, Cloudflare adds the CF-Connecting-IP header.

So you can implement custom IP resolver which attempts to read the CF-Connecting-IP header or fallbacks with the internal IP resolver:

Here is the service declaration. It decorates the internal resolver:

Symfony HttpClient integration

If you have a dependency on symfony/http-client in your application then it will be automatically wired to use via RequestMethod/SymfonyHttpClient.

Troubleshooting checklist

Make sure you setup recaptcha key/secret of version 3.

Also, make sure you added the domain you use in the recaptcha settings. Usually dev domain differs from the production one, so better to double check. image

Make sure you are seeing this in the html of your rendered form

Make sure you don't have javascript errors in the browser console

Testing


All versions of karser-recaptcha3-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
google/recaptcha Version ^1.2
symfony/form Version ^3.4|^4.0|^5.0|^6.0|^7.0
symfony/framework-bundle Version ^3.4.26|^4.2.7|^5.0|^6.0|^7.0
symfony/expression-language Version ^3.4|^4.0|^5.0|^6.0|^7.0
symfony/yaml Version ^3.4|^4.0|^5.0|^6.0|^7.0
symfony/validator Version ^3.4|^4.0|^5.0|^6.0|^7.0
symfony/twig-bundle Version ^3.4|^4.0|^5.0|^6.0|^7.0
twig/twig Version ^2.9|^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package karser/karser-recaptcha3-bundle contains the following files

Loading the files please wait ....