beingnikhilesh/googlerecaptcha

Google reCAPTCHA PHP 库,用于验证用户响应是否符合 Google reCAPTCHA v3。

v0.0.1 2024-09-13 11:52 UTC

This package is auto-updated.

Last update: 2024-09-13 11:53:16 UTC


README

一个 PHP 库,可以无缝地调用 Google Recaptcha 服务,并验证用户是真人还是机器人。

什么是 Google Recaptcha

Google reCAPTCHA 是一项服务,通过验证用户是真人还是机器人来帮助网站防止垃圾邮件和滥用。它通过一系列对人类容易但对机器人困难的挑战来实现。

特性

  • Google reCAPTCHA v3 集成
  • 可配置的阈值分数 用于垃圾邮件检测
  • 模块化结构 便于集成和定制

要求

  • PHP 7.4 或更高版本
  • Composer
  • Google reCAPTCHA API 密钥(密钥 & 网站密钥)
  • Guzzle HTTP 客户端

安装

建议通过 Composer 安装此库

  composer require beingnikhilesh\GoogleRecaptcha

使用/示例

import Component from 'my-project'

function App() {
  return <Component />
}

库使用/示例

  1. 打开 config.php 文件,并编辑从 Google Recaptcha 网站收到的 Google 密钥和 Google 密钥。

  2. 使用以下代码获取 Veridy 以确定是否是真人或机器人

use beingnikhilesh\GoogleRecaptcha\GoogleRecaptcha;

/**
* Pass the $token and $action to the Validate Function
* @$token Token received from POST Request
* @$action passed in View page and received via POST Request
*
* @ response    TRUE  - If request is Human
*               FALSE - If the request is ROBOT
*/  
$isValid = GoogleRecaptcha::_validate($token, $action);

/*
* Additionally if you want to Pass the Google Secret and Google Key Manually Everytime, you can do so as below
* @$googleSecret    Google Secret recieved from Google Recaptcha Site 
* @$googleKey       Google Key recieved from Google Recaptcha Site
*
* @return           NULL
*/
GoogleRecaptcha::credentials($googleSecret, $googleKey);

如何实现 Google Recaptcha

更多关于如何实现 Google Recaptcha 的详细信息

许可

GoogleRecaptcha 在 MIT 许可证下提供(MIT