crabstudio/recaptcha 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

crabstudio/recaptcha

最新稳定版本:4.1.0

Composer 安装命令:

composer require crabstudio/recaptcha

包简介

Easily use Google Recaptcha in CakePHP projects

README 文档

README

Build Status Latest Stable Version Total Downloads License

Integrate Google Recaptcha v2 to your CakePHP project

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require crabstudio/recaptcha

Load plugin

From command line:

bin/cake plugin load Recaptcha

Load Component and Configure

Override default configure from loadComponent:

$this->loadComponent('Recaptcha.Recaptcha', [ 'enable' => true, // true/false 'sitekey' => 'your_site_key', //if you don't have, get one: https://www.google.com/recaptcha/intro/index.html 'secret' => 'your_secret', 'type' => 'image', // image/audio 'theme' => 'light', // light/dark 'lang' => 'en', // default 'en' 'size' => 'normal' // normal/compact 'callback' => null, // `callback` data attribute for the recaptcha div, default `null` 'scriptBlock' => true // Value for `block` option for HtmlHelper::script() call ]);

Override default config from app config file:

// file: config/app.php /**  * Recaptcha configuration.  */ 'Recaptcha' => [ 'sitekey' => 'your_site_key', 'secret' => 'your_secret', 'type' => 'image', 'theme' => 'light', 'lang' => 'es', 'size' => 'normal' ]

Override default configure from recaptcha config file:

// file: config/recaptcha.php return [ /**  * Recaptcha configuration.  *  */ 'Recaptcha' => [ 'enable' => true, 'sitekey' => 'your_site_key', 'secret' => 'your_secret', 'type' => 'image', 'theme' => 'light', 'lang' => 'es', 'size' => 'normal' ] ];

Load recaptcha config file:

// file: config/bootstrap.php Configure::load('recaptcha', 'default', true);

Config preference:

  1. loadComponent config options
  2. recaptcha config file
  3. app config file

Usage

Display recaptcha in your template:

 <?= $this->Form->create() ?> <?= $this->Form->control('email') ?> // Display recaptcha box in your template, if configure has enable = false, nothing will be displayed <?= $this->Recaptcha->display() ?> <?= $this->Form->button() ?> <?= $this->Form->end() ?>

Verify in your controller function

 public function forgotPassword() { if ($this->request->is('post')) { if ($this->Recaptcha->verify()) { // if configure enable = false, it will always return true //do something here } $this->Flash->error(__('Please pass Google Recaptcha first')); } }

Done.

统计信息

  • 总下载量: 108.99k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 20
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 4

GitHub 信息

  • Stars: 20
  • Watchers: 2
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固