zoukankan      html  css  js  c++  java
  • laravel captcha 验证码制作

    我们将以第三方扩展包 mews/captcha 作为基础来实现 Laravel 中的验证码功能。

    使用 Composer 安装:composer require "mews/captcha:~2.0"

    运行以下命令生成配置文件 config/captcha.php:php artisan vendor:publish --provider='MewsCaptchaCaptchaServiceProvider' 

    我们可以打开配置文件 config/captcha.php ,查看其内容:

    characters 选项是用来显示给用户的所有字符串,default, flat, mini, inverse 分别是定义的四种验证码类型,你可以在此修改对应选项自定义验证码的长度、背景颜色、文字颜色等属性。

    在视图中插入验证码:

    <img  class="captcha"  src="{{ captcha_src('flat') }}"  onclick="this.src='/captcha/flat?'+Math.random()"  title="点击图片更新验证码">

    在浏览器的效果:

    <img  class="captcha"  src="/captcha/flat?0.7568626010802726"  onclick="this.src='/captcha/flat?'+Math.random()"  title="点击图片更新验证码">

    captcha_src() 方法是 mews/captcha 提供的辅助方法,用于生成验证码图片链接,参数为 captcha.php 中的四种验证码类型之一。

    onclick() 是 JavaScript 代码,实现了点击图片更新验证码的功能,允许用户在验证码太难识别的情况下换一张图片试试。Math.random() 返回值为 0.0 ~ 1.0 之间的一个伪随机数。

  • 相关阅读:
    随机数生成器
    赌博的艺术
    基本算法——包罗万象
    对于搜索的新理解
    关于动态规格的新理解
    发现的好东西——bitset
    高精度(重定义版)——来自
    ac自动机(模板)
    数据采集框架Gobblin简介
    Hadoop的数据采集框架
  • 原文地址:https://www.cnblogs.com/muwu/p/9032095.html
Copyright © 2011-2022 走看看