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.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.phplang/vendor/ir-captcha/en/messages.phpresoures/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
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 klangch/laravel-ir-captcha 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
Two Captcha
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
Laravel 5 Securimage helper
统计信息
- 总下载量: 478
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-28