承接 hostkurd/flocms-captcha 相关项目开发

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

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

hostkurd/flocms-captcha

Composer 安装命令:

composer require hostkurd/flocms-captcha

包简介

Image captcha package for FloCMS guest form verification.

README 文档

README

A lightweight, framework-friendly image captcha package for FloCMS.
Designed for secure guest form verification with minimal dependencies.

✨ Features

  • Simple image-based captcha (GD powered)
  • Fully customizable (size, fonts, characters, noise, etc.)
  • Session-based verification
  • Framework-agnostic (works outside FloCMS too)
  • PSR-4 autoloaded
  • Extensible renderer system (future support for other drivers)

📦 Installation

Install via Composer:

composer require hostkurd/flocms-captcha

Requirements

  • PHP >= 8.1
  • GD extension enabled (ext-gd)

🚀 Quick Start

1. Create captcha instance

use FloCMS\Captcha\CaptchaManager;

$captcha = new CaptchaManager();

2. Output captcha image

Create a simple endpoint:

// public/captcha.php

require dirname(__DIR__) . '/vendor/autoload.php';

use FloCMS\Captcha\CaptchaManager;

$captcha = new CaptchaManager();
$captcha->output();

3. Display in form

<img src="/captcha.php" alt="Captcha">
<input type="text" name="captcha" required>

4. Verify input

use FloCMS\Captcha\CaptchaManager;

$captcha = new CaptchaManager();

if (!$captcha->verify($_POST['captcha'] ?? null)) {
    die('Invalid captcha');
}

5. Clear after success

$captcha->clear();

⚙️ Configuration

You can override default settings by passing a config array:

$captcha = new CaptchaManager([
    'length' => 5,
    'width' => 200,
    'height' => 60,
]);

Default Configuration

return [
    'length' => 6,
    'width' => 180,
    'height' => 50,
    'font_size' => 24,
    'angle_min' => -15,
    'angle_max' => 15,
    'noise_lines' => 8,
    'session_key' => 'flocms_captcha',
    'characters' => 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789',
    'case_sensitive' => false,
    'fonts' => [
        __DIR__ . '/../public/fonts/Acme.ttf',
        __DIR__ . '/../public/fonts/PlayfairDisplay.ttf',
        __DIR__ . '/../public/fonts/Ubuntu.ttf',
    ],
];

🧠 How It Works

  1. A random captcha string is generated
  2. The string is stored in session
  3. An image is rendered using GD
  4. User submits input
  5. Input is compared securely using hash_equals

🔐 Security Notes

  • Uses random_int() for cryptographically secure randomness
  • Uses hash_equals() to prevent timing attacks
  • Case-insensitive comparison by default (configurable)
  • Always use CSRF protection alongside captcha

🧩 Architecture

FloCMS\Captcha\
├── Captcha.php          // Logic (generate, store, verify)
├── CaptchaManager.php   // Facade / main API
├── Renderer\
│   ├── RendererInterface.php
│   └── GdRenderer.php   // Image rendering (GD)

🔄 Session Handling

By default, the package uses native PHP sessions:

$_SESSION['flocms_captcha']

Session is automatically started if not already active.

📁 Fonts

Fonts are included inside the package:

public/fonts/

You can replace or extend them:

$captcha = new CaptchaManager([
    'fonts' => [
        '/path/to/custom/font1.ttf',
        '/path/to/custom/font2.ttf',
    ]
]);

🔌 Extending (Custom Renderer)

You can create your own renderer by implementing:

FloCMS\Captcha\Renderer\RendererInterface

Example:

use FloCMS\Captcha\Renderer\RendererInterface;

class CustomRenderer implements RendererInterface
{
    public function render(string $text): void
    {
        // your rendering logic
    }
}

Then inject it:

$captcha = new CaptchaManager([], new CustomRenderer());

🧪 Example

Run the included example:

php -S localhost:8000 -t examples

Then open:

http://localhost:8000/basic.php

🏗️ Integration with FloCMS

Recommended usage:

  • Keep captcha as a separate package
  • Use alongside:
    • flocms-core (Session, CSRF, Validation)
  • Expose via route or public/captcha.php

❌ What NOT to Do

Avoid placing captcha inside:

public/themes/default/

Captcha is application logic, not a theme asset.

🛣️ Roadmap

  • Session adapter (FloCMS Session integration)
  • Multiple captcha drivers (SVG, math captcha, etc.)
  • API-based captcha (future support)
  • Rate limiting / anti-bruteforce
  • Audio captcha support

🤝 Contributing

Contributions are welcome.

  • Fork the repository
  • Create a feature branch
  • Submit a pull request

📄 License

MIT License

👤 Author

HostKurd

💡 Final Note

This package is intentionally lightweight and modular.
Use it as a drop-in captcha solution or extend it to fit your framework needs.

hostkurd/flocms-captcha 适用场景与选型建议

hostkurd/flocms-captcha 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-19