htmlwebfan/nocaptcha

Generates and verifies a NoCaptcha field in forms HTML forms with PHP.

v1.0.1 2015-07-12 12:46 UTC

This package is not auto-updated.

Last update: 2024-04-13 14:34:34 UTC


README

Latest Version Software License

Are you a robot? Introducing "No Captcha reCaptcha".

This PHP package allows you to render a form field in a form and then verify the response from Google on your server. The package supports psr-4.

reCAPTCHA from Google

Install

To get the latest version of nocaptcha simply require it in your composer.json file.

"htmlwebfan/nocaptcha": "dev-master"

You'll then need to run composer install to download it and have the autoloader updated.

Usage

Overview

  1. Configure NoCaptcha
  2. Display the nocaptcha filed on the form
  3. When the form is posted to your processor script, verify that the nocaptcha response is valid

Configure

Open the Config.php file and set the constants with the the sitekey and the secret values you got from Google Google

Display

// form_page.php

// Instantiate a NoCaptcha object and initialize it with the Config 
// object containing your keys
$nb = new NoCaptcha(new Config);  

// Generate the HTML code for your nocaptcha form field
$nb->generateField();

// When the user successfully completes the turing test, Google will set a 
// g-recaptcha-response on your form that will be posted to your processing script

Verify captcha from the server

// processor_script.php

// The value Google gave you on the form when the user completed the test
$r = $_POST['g-recaptcha-response']; 

// Do not forget to filter your input here, I have not done so here in order 
// to keep the example simple
$em = $_POST['email'];

$nobot = new NoCaptcha(new Config);
$nobot->setResponse($r);
$v = $nobot->verify();

// verify() returns a stdCalss Object with a success property with a value of 1
// Any other value means the verification failed. The class has a debug() method 
// for troubleshooting failures like so:

$nobot->debug()

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email nocaptcha@htmlwebfan.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.