承接 ivanamat/cakephp-captcha 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ivanamat/cakephp-captcha

最新稳定版本:2.0

Composer 安装命令:

composer require ivanamat/cakephp-captcha

包简介

CakePHP 4.5.x - reCAPTCHA plugin

README 文档

README

Installation

Composer

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

The recommended way to install composer packages is:

composer require ivanamat/cakephp-captcha

Git submodule

git submodule add git@github.com:ivanamat/cakephp-captcha.git plugins/Captcha
git submodule init
git submodule update

Getting started

Get reCAPTCHA secret at https://www.google.com/recaptcha

Configure

Set the secret in your config/bootstrap.php file.

    Configure::write('Captcha.secret','MY_SECRET_KEY');

Load Component

Load component in the initialize() function

    class MyController extends AppController {

        public function initialize() {
            parent::initialize();

            $this->loadComponent('Captcha.Captcha');
        }

    }

...or load the component in the array of components.

    class MyController extends AppController {

        public $components = [
            'Captcha' => [
                'className' => 'Captcha.Captcha'
            ]
        ];

    }

Easy to use

Controller

    # MyController

    $ip = getenv('REMOTE_ADDR');
    $gRecaptchaResponse = $this->request->data['g-recaptcha-response'];

    $captcha = $this->Captcha->check($ip,$gRecaptchaResponse);

    if($captcha->errorCodes == null) {
        // Success
    } else {
        // Fail! Maybe a bot?
    }

HTML

Paste this snippet before the closing tag </head> in the HTML template

    <script src='https://www.google.com/recaptcha/api.js'></script>

Paste this snippet at the end of the <form> where you want the reCAPTCHA widget to appear. Replace YOUR-SITEKEY with your own site key.

    <div class="g-recaptcha" data-sitekey="YOUR-SITEKEY"></div>

About CakePHP 4.x - reCAPTCHA

CakePHP 4.x - Captcha uses the reCAPTCHA third-party library.
You can download reCAPTCHA from official website: [https://github.com/google/recaptcha)

Google reCAPTCHA

Contributors

Iván Amat on GitHub and www.ivanamat.es
BusaniPrepaid on GitHub

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

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