承接 klangch/laravel-ir-captcha 相关项目开发

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

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

klangch/laravel-ir-captcha

Composer 安装命令:

composer require klangch/laravel-ir-captcha

包简介

Image rotation captcha library for Laravel 11/12

README 文档

README

Laravel IR Captcha (Image Rotation Captcha) is a customizable image rotation CAPTCHA package for Laravel 11 and 12.

Features

  • Interactive, intuitive, and more user-friendly than classic text-based CAPTCHAs.
  • Customizable UI and flexible configuration.
  • No third-party services required. Everything are handled locally.

Preview

LaravelIRCaptcha Screenshot 1 LaravelIRCaptcha Screenshot 2

LaravelIRCaptcha.Demo.mp4

Installation

Make sure the PHP gd extension is installed and enabled.

Install with composer using following command:

composer require klangch/laravel-ir-captcha

Configuration

Publish configuration, view, localization files by using following command:

$ php artisan vendor:publish --provider="Klangch\LaravelIRCaptcha\LaravelIRCaptchaServiceProvider"
  • config/ir-captcha.php
  • lang/vendor/ir-captcha/en/messages.php
  • resoures/views/vendor/ir-captcha/irCaptcha.blade.php

Usage

Show captcha in iframe

<iframe src="{{ ir_captcha()->iframeUrl() }}" height="290" width="300"></iframe>

Listen for iframe's post message

window.addEventListener("message", (event) => {
    if (event.data && event.data.type === "irCaptcha" && event.data.status === "success") {
        // Get captcha token and set to input field
        document.querySelector("input[name='captcha_token']").value = event.data.captchaToken;

        // Continue form submission...
    }
});

URL for iframe

// Get captcha URL with helper
ir_captcha()->iframeUrl();

// Get captcha URL with parent origin and dark theme
ir_captcha()->iframeUrl('https://[your_parent_origin].com', true);

// Or append parent origin and dark theme param manually
$url = ir_captcha()->iframeUrl() . '?parent_origin=https://[your_parent_origin].com&theme=dark';

or set dark theme dynamically in Laravel Blade + JS

// Get captcha URL with helper
let captchaUrl = "{{ ir_captcha()->iframeUrl() }}";

// Or without helper
let captchaUrl = "https://[your_captcha_domain].com/ir-captcha";

// Then append parent origin
captchaUrl += "?parent_origin=" + window.location.origin;

// Append theme
if (themeMode === "dark") {
    captchaUrl += "&theme=dark";
}

document.getElementById("captchaIframe").src = captchaUrl;

Validate captcha token

if (ir_captcha()->validateCaptchaToken($token) === true) {
    // Validation success
}

or by using Laravel validation rule:

use Illuminate\Support\Facades\Validator;
use Klangch\LaravelIRCaptcha\Rules\IRCaptcha;

$rules = [
    'captcha_token' => ['required', new IRCaptcha],
];

$validator = Validator::make($request->all(), $rules);
$validator->validate();

Clear expired captcha files

Clear expired captcha files by using following command:

$ php artisan ir-captcha:clear-expired

You can set this command in cron job to regularly clear expired files.

⚠️ Note For Frontend Framework On Different Domains ⚠️

When using this package with frontend hosted on different domain (such as a Next.js app embedding captcha verification page via an iframe), there are a few important things to keep in mind:

⚠️ CSRF Exclusion

CSRF protection may block requests due to cross-origin restrictions. To allow verification requests from the iframe to bypass CSRF validation, you can explicitly exclude the verification endpoint:

// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    // ...

    $middleware->validateCsrfTokens(except: [
        'ir-captcha-verify',
    ]);
});

⚠️ Set Captcha Locale

You can set the captcha's language by passing a locale code as a query string parameter, such as _lang. Then, use middleware to set the application's locale accordingly.

For example, in your HTML:

<iframe src="https://[your_captcha_domain].com/ir-captcha?parent_origin=https://[your_parent_origin].com&_lang=cn"></iframe>

In your middleware, retrieve the _lang value and set the application locale:

public function handle(Request $request, Closure $next): Response
{
    $locale = $request->input('_lang', 'en');
    App::setLocale($locale);
    return $next($request);
}

For a complete working example, see the Code Example repository.

Code Example

https://github.com/kleong153/laravel-ir-captcha-example

klangch/laravel-ir-captcha 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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