定制 miladrahimi/laracaptcha 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

miladrahimi/laracaptcha

最新稳定版本:1.1

Composer 安装命令:

composer require miladrahimi/laracaptcha

包简介

Free Laravel captcha for neat and powerful projects!

README 文档

README

Laravel simple captcha

Documentation

LaraCaptcha is an easy-to-use captcha creator package for Laravel framework. It is built based on Laravel APIs and you can use it alongside Laravel facilities. LaraCaptcha using image based captcha to protect you from spams.

Installation

Run Terminal (Linux Based Environment) or Command Prompt (Windows OS) for your project's root where you can see `composer.json' file. Then run following command:

composer require miladrahimi/laracaptcha

After adding the package to your project, you need to add LaraCaptcha provider to your project's providers. To do that, open config/app.php file and append following code to the list of providers.

Laravel <= 5.0

'MiladRahimi\LaraCaptcha\Provider',

Laravel => 5.1

MiladRahimi\LaraCaptcha\Provider::class,

Captcha Image

You need to display a captcha image in your HTML forms, so LaraCaptcha provides a image url like what you see below that you can use easily.

http://your-project.com/laracaptcha.png

You may use Laravel url() function in Blade template system to resolve this URL.

{{ url('/laracaptcha.php') }}

So your captcha image should be like this:

<img src="{{ url('/laracaptcha.php') }}">

Random URL and caching problem

If you use methods mentioned above you will face to caching problem very soon. As it's needed every captcha must be a different thing when user reloads the page or press refresh button. But sometimes user browsers like Firefox and Chrome cache the image so users see the same image while server has created new image.

You may ask what should I do now? That's a good question! You have to add a fake parameter to the image url and pass a random value like following example:

http://your-project.com/laracaptcha.png?r=65442

To do it in Blade template system:

url('/laracaptcha.png?r=' . rand(0, 100000))

So your captcha image should be like this:

<img src="{{ url('/laracaptcha.png?r=' . rand(0, 100000)) }}">

Refresh Button

If you don't need to refresh button for you captcha skip this section.

You are still here so you need it!

I consider you have created a button in your page Blade like this:

<button type="button" id="refresh">Refresh</button>

So you need to add following jQuery code to your page:

<script>
    $("#refresh").click(function () {
        $("#captcha").attr("src", '/laracaptcha.png?r=' + Math.random());
    });
</script>

Validation

Now it's time to validate user input. I hope you use Laravel validation rules, so you can use laraCaptcha rule just like this:

$validator = Validator::make(Request::all(), [
    'captcha' => 'required|laraCaptcha',
]);
if ($validator->fails()) {
    // On error
} else {
    // No error
}
  • captcha is the name of HTML form field.

Of course there is one step left. You should add a user-friendly error message if the user entered wrong captcha. To do this, open resources/lang/en/validation.php and add following item to the existent array.

"laracaptcha" => "You entered the security code incorrectly.",

Of course you are able to use :attribute in the validation message instead.

This approach enables you to use Laravel internationalization tools.

Homepage

Contributors

License

LaraCaptcha is released under the MIT License.

miladrahimi/laracaptcha 适用场景与选型建议

miladrahimi/laracaptcha 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 65 次下载、GitHub Stars 达 4, 最近一次更新时间为 2015 年 09 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 miladrahimi/laracaptcha 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-24