lubosdz/yii2-captcha-extended 问题修复 & 功能扩展

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

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

lubosdz/yii2-captcha-extended

Composer 安装命令:

composer require lubosdz/yii2-captcha-extended

包简介

Extended captcha code generator for Yii2 framework with configurable obfuscation level

README 文档

README

Yii2 Captcha Extended is an extension written for Yii2 framework. It enhances original captcha code delivered along with the framework - see DEMO. Version for Yii 1.x is available at Yii Framework Extensions.

Features

  • supports modes: default, math, mathverbal, words, logical
  • supports extended characters latin1, latin2 (utf-8) including middle- east- european and cyrillyc characters
  • adds visual obfuscation elements: dots density, through lines, fillSections, random text & background color
  • mode-dependent options: randomUpperLowerCase (default mode), resultMultiplier (math mode)

Screenshot Screenshot
Screenshot Screenshot
Screenshot
Screenshot

INSTALLATION

  1. Install via composer:
$ composer require "lubosdz/yii2-captcha-extended" : "~1.0.0"

or you can include the following in your composer.json file:

{
	"require": {
		"lubosdz/yii2-captcha-extended" : "~1.0.0"
	}
}
  1. Define action in controller, e.g. SiteController:
public function actions()
{
	return [
		'captcha' => [
			'class' => 'lubosdz\captchaExtended\CaptchaExtendedAction',
			// optionally, set mode and obfuscation properties e.g.:
			'mode' => 'math',
			//'mode' => CaptchaExtendedAction::MODE_MATH,
			//'resultMultiplier' => 5,
			//'lines' => 5,
			//'density' => 10,
			//'height' => 50,
			//'width' => 150,
		],
	];
}
  1. Define client validation in LoginForm::rules():
public $verifyCode;

public function rules()
{
	return [
		['verifyCode', 'lubosdz\captchaExtended\CaptchaExtendedValidator',
			'captchaAction' => Url::to('/site/captcha'),
		],
	];
}
  1. In view defined captcha field inside login form e.g.:
<?php $form = ActiveForm::begin() ?>

// ...

<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
	'captchaAction' => Url::to('/site/captcha'),
	'template' => '<div class="text-center">{image}</div><br/> {input} ',
	'imageOptions' => [
		'class' => 'img-fluid',
		'style' => 'cursor:pointer; width: 100%',
		'title' => Yii::t('app', 'Click to refresh the code'),
	],
	'options' => [
		'placeholder' => Yii::t('app', 'Verification code'),
		'class' => 'form-control',
	],
])->label(false) ?>

// ...

<?php ActiveForm::end(); ?>
  1. If needed, collect localized strings via CLI command yiic message messages/config.php and translate captcha related strings.

  2. Since by default capchta configures to default framework's settings, you may want to adjust some options:

    • mode - default|math|mathverbal|logical|words,
      • for the words mode, you can replace your own file [words.txt] or [words.yourlanguage.txt]
    • density - dots density [0-100],
    • lines - the number of through lines [0-20],
    • fillSections - the number of fillSections [0-20],
    • letters - define your own first characters set (UTF-8 supported)
    • vowels - define your own second characters set (UTF-8 supported)
    • resultMultiplier - applied to math mode to increase formula difficulty
    • fileWords - abs. path to file with your own defined locale words (UTF-8 supported)
    • randomUpperLowerCase - mix up randomly upper & lower characters from characters sets
    • paramRefreshUrl - set your own URL refresh param, defaults to v
    • also note standard properties supported by framework: width, height, padding, offset, foreColor, backColor, transparent, minLength, maxLength, ..
  3. Enjoy! :-)

Changelog

Version 1.0.5 - Nov 7, 2023

  • PHP 8.2+ compatability
  • enable unicode in REGEX by default (/u modifier)

Version 1.0.4 - Jun 30, 2021

  • updated SK, CS words (dropped accented characters)

Version 1.0.3 - Jun 07, 2020

  • minor compatability fix for PHP 7.4+

Version 1.0.2 - Feb 25, 2020

  • configurable refresh parameter in URL
  • updated docs

Version 1.0.1 - May 21, 2018

  • added CS (Czech) words file
  • center formula horizontaly
  • updated documentation

Version 1.0.0 - March 28, 2018

  • rework of previous extension for Yii 1.x branch
  • added new options - custom character sets, resultMultiplier, randomUpperLowerCase, Imagick support
  • couple of potential bugfixes e.g. calculating pixel color ranges
  • full multibyte (MB) support
  • added support for installation via composer

lubosdz/yii2-captcha-extended 适用场景与选型建议

lubosdz/yii2-captcha-extended 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.81k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2018 年 03 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 18.81k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 40
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2018-03-30