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

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

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

inimist/cakephp-captcha

Composer 安装命令:

composer require inimist/cakephp-captcha

包简介

CakePHP Captcha Plugin, Image, Math and Google Recaptcha Support

README 文档

README

Bot Detect using Image captcha, Math captcha and Google-recaptcha for CakePHP 3

Why to use this plugin?

  • To display Google Recaptcha / Image Captcha / Math Challenge for web forms

This CakePHP Captcha plugin requires CakePHP 3.6+.

Quick Features

  • No Custom Code required.
  • Quick install. Just add 3 lines, on each in Controller, Model and View.
  • Works as Model Validation.
  • Multiple Captchas on single page.
  • Multiple Demo available.
  • Demo available as CakePHP Plugin.

Installation

composer require inimist/cakephp-captcha

and

bin/cake plugin load Captcha -b -r

Implementation

  1. Load Captcha plugin.

    If you ran bin/cake plugin load Captcha -b -r above skip this step.

    Place Plugin::load('Captcha'); in your application's Application.php or bootstrap.php file.

  2. Load Capthca component

    Place $this->loadComponent('Captcha.Captcha'); in your controllerr's initialize function

    OR

    Load Captcha component on the fly, in the particular controller action function. For example in the signup() action:

    $this->loadComponent('Captcha.Captcha'); //or load on the fly!$

  3. Add Behavior to your Model/Table

    Place $this->addBehavior('Captcha.Captcha', ['field'=>'<fieldname>']) in your Model (Table class) Note: If you use Google Recaptcha add "secret" option with its value which you get from Google. Also, add Google site key in the view file.

  4. Create an input field in your view's form as:

    echo $this->Captcha->create('<fieldname>', $options);

  5. In your controller in which your form data is processed, place (required with image and math catpcha):

    $this->Users->setCaptcha('<fieldname>', $this->Captcha->getCode('<fieldname>'));

    just before patching entity. For example:

    $this->Users->setCaptcha('securitycode', $this->Captcha->getCode('securitycode'));
    $user = $this->Users->patchEntity($user, $this->request->data);
    

A fully working demo can be found here. You can install a fully working demo as a plugin from here.

Settings

The best place for settings is your_apps/config/app.php file. Create a new key named "Captcha" and specify settings there.

'Captcha' => [
    'type' => 'recaptcha',
    'sitekey' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    //'clabel' => 'Enter code',
    //'reload_txt' => 'Reload??'
]

More examples

Options:

$options['width']=150;
$options['height']=50;
$options['theme']='default';
echo $this->Captcha->create('captcha_input_field_name', $options);

Multiple Captchas on same page:

//form 1
$options1['width']=150;
$options1['height']=50;
echo $this->Captcha->create('captcha_input_field_name1', $options1);

//form 2, A math captcha, anywhere on the page
$options2['type']='math';
echo $this->Captcha->create('captcha_input_field_name2', $custom2);

Options for view template. Ex: $this->Captcha->create('field_name', $options):

  • field: field name (Optional. Default "captcha")
  • type: recaptcha/image/math (Optional: Default "image")
  • width: width of image captcha (Optional. Applies to type "image" only)
  • height: height of image captcha (Optional. Applies to type "image" only)
  • theme: default/random image captcha color pattern (Optional. Applies to type "image" only ; default "default")
  • length: number of characters in image captcha (Optional. Applies to type "image" only)
  • angle: angle of rotation for characters in image captcha (Optional. Applies to type "image" only)
  • fontAdjustment: Font size for Image Captcha (Optional. Applies to type "image" only)
  • reload_txt: Reload Captcha Text (Optional)
  • clabel: Label for Image Captcha field (Optional)
  • mlabel: Label for Math Captcha field (Optional)
  • sitekey: Googel Recaptcha Sitekey (Required. Applies to type "recatpcha" only)

(All above options can also be set from controller. Ex: $this->loadComponent('Captcha.Captcha', $options))

**Options for model. Ex: $this->addBehavior('Captcha.Captcha', $options);

  • field: field name (optional: default "captcha")
  • secret: Googel Recaptcha Secret (required for type "recatpcha")

Known Issues:

  1. Headers already sent issue. The component uses php's header() function to send or generate captcha image as raw HTML output. Make sure there is no output generated before the create() function in your component. It is common error to have spaces, tags or empty space in your files which would cause rending no image in the captcha.

  2. GD library and True Type Font (TTF) support extensions are enabled in PHP.

  3. This captcha script uses three random font faces, anonymous, droidsans and ubuntu to generate fonts in the captcha images. These font faces are placed in the captcha/src/Lib/Fonts of this download. I have seen that, sometimes, these font files get corrupted during downloads. If you see font not found error in your error logs and captcha are failed to generate, try downloading these font faces from their respective sources and replace them in the mentioned folder. You can also use different font families by placing them Fonts folder and referencing them in the CaptchaComponent.php component file.

inimist/cakephp-captcha 适用场景与选型建议

inimist/cakephp-captcha 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 553 次下载、GitHub Stars 达 3, 最近一次更新时间为 2018 年 06 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「security」 「plugin」 「recaptcha」 「cakephp」 「captcha」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 inimist/cakephp-captcha 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 inimist/cakephp-captcha 我们能提供哪些服务?
定制开发 / 二次开发

基于 inimist/cakephp-captcha 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 553
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 4
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-23