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 之间的一个伪随机数。

  • 相关阅读:
    poj 3669 Meteor Shower
    poj 3009 Curling 2.0
    poj 1979 Red and Black
    区间内素数的筛选
    九度oj 题目1347:孤岛连通工程
    poj 3723 Conscription
    poj 3255 Roadblocks
    Luogu P3975 [TJOI2015]弦论
    AT2165 Median Pyramid Hard 二分答案 脑洞题
    后缀自动机多图详解(代码实现)
  • 原文地址:https://www.cnblogs.com/muwu/p/9032095.html
Copyright © 2011-2022 走看看