htmlwebfan/nocaptcha

使用PHP在HTML表单中生成并验证NoCaptcha字段。

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

This package is not auto-updated.

Last update: 2024-09-28 16:51:50 UTC


README

Latest Version Software License

你是机器人吗?介绍"No Captcha reCaptcha"。

此PHP包允许您在表单中渲染一个表单字段,然后验证来自Google的响应。该包支持psr-4。

reCAPTCHA from Google

安装

要获取nocaptcha的最新版本,只需在您的composer.json文件中引入它。

"htmlwebfan/nocaptcha": "dev-master"

然后您需要运行composer install来下载它并更新自动加载器。

用法

概述

  1. 配置NoCaptcha
  2. 在表单上显示nocaptcha字段
  3. 当表单提交到您的处理器脚本时,验证nocaptcha响应是否有效

配置

打开Config.php文件,并使用从Google(Google)获取的sitekey和secret值设置常量

显示

// 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

从服务器验证captcha

// 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

安全

如果您发现任何与安全相关的问题,请通过电子邮件nocaptcha@htmlwebfan.com联系,而不是使用问题跟踪器。

鸣谢

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件