TP5.0框架下的think-captcha验证码扩展包

2024-02-21 06:48

本文主要是介绍TP5.0框架下的think-captcha验证码扩展包,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

之前在进行前端登陆页面实现的过程中,用到了TP5.0自带的think-captcha验证码包,现在在这里补充上介绍和用法。

首先,如果你是TP5.05之前的版本,需要自己去下载captcha,如果想从通过命令行直接下载需要安装composer,5.05之后的版本会自带think-captcha包。

thinkphp\vendor\topthink\think-capcha

1.html中验证码的显示:

<div>{:captcha_img()}</div>


<div><img src="{:captcha_src()}" alt="captcha" /></div>

2.验证码判断

js方法:

function check_verify($code, $id = ''){$captcha = new Captcha();return $captcha->check($code, $id);
}


或直接在php中使用tp5.0封装的 captcha_check()方法来判断用户输入的验证码是否正确

3.验证码配置

config.php

通过对验证码配置的修改可以实现自定义验证码。

4.博主实现的验证码实例:

点击图片可以切换验证码:

实现验证码随机切换:

在点击img图片时,把当前验证码图片加一个随机数,从而切换成任意新的验证码图片

代码:

.html:

<div class="form-bottom"><form role="form" action="{:url('check')}" method="post" class="login-form"><div class="form-group"><label class="sr-only" for="form-username">Username</label><input type="text" name="name" placeholder="用户名/邮箱/手机号" class="form-control" id="form-username"><div class="loginerror" style="display: none;">用户名不存在</div></div><div class="form-group"><label class="sr-only" for="form-password">Password</label><input type="password" name="pass" placeholder="密码" class="form-password form-control" id="form-password"></div><div class="form-group"><label class="sr-only" for="form-password">Code</label><input type="text" name="code" placeholder="验证码" class="form-password form-control" id="form-code"><img src="{:captcha_src()}" alt="captcha" οnclick="this.src=this.src+'?'+Math.random()" style="margin: 5px;height: 50px;width: 200px;"/></div><div class="form-group"><label class="radio-inline"><input type="radio" name="r" id="r1" value="option1" checked> 用户</label><label class="radio-inline"><input type="radio" name="r" id="r2"  value="option2"> 管理员</label></div>
<!--                                 <div><label class="radio-inline"><input type="radio" name="user" id="r1" value="user" checked>用户</label><label class="radio-inline"><input type="radio" name="manager" id="r2" value="manager">管理员</label>  </div> --><button type="submit" class="btn">登陆</button><div><p id="form-p"><a href="#">忘了密码?</a> | <a href="../register/register.html">注册账号</a> | <a href="../register/test.html">意见反馈</a></p></div></form>


.php:

    public function checkCode(){$code=input('post.code');//验证码判断if(captcha_check($code)){//echo"验证码正确";//echo"<hr>";echo "<script>alert('登陆成功!!!!!!!!!!');</script>";return true;}else{echo "<script>alert('验证码错误');history.go(-1);</script>";return false;}}

 

这篇关于TP5.0框架下的think-captcha验证码扩展包的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/730893

相关文章

PostgreSQL的扩展dict_int应用案例解析

《PostgreSQL的扩展dict_int应用案例解析》dict_int扩展为PostgreSQL提供了专业的整数文本处理能力,特别适合需要精确处理数字内容的搜索场景,本文给大家介绍PostgreS... 目录PostgreSQL的扩展dict_int一、扩展概述二、核心功能三、安装与启用四、字典配置方法

Spring 框架之Springfox使用详解

《Spring框架之Springfox使用详解》Springfox是Spring框架的API文档工具,集成Swagger规范,自动生成文档并支持多语言/版本,模块化设计便于扩展,但存在版本兼容性、性... 目录核心功能工作原理模块化设计使用示例注意事项优缺点优点缺点总结适用场景建议总结Springfox 是

Python的端到端测试框架SeleniumBase使用解读

《Python的端到端测试框架SeleniumBase使用解读》:本文主要介绍Python的端到端测试框架SeleniumBase使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全... 目录SeleniumBase详细介绍及用法指南什么是 SeleniumBase?SeleniumBase

Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析

《Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析》InstantiationAwareBeanPostProcessor是Spring... 目录一、什么是InstantiationAwareBeanPostProcessor?二、核心方法解

Python验证码识别方式(使用pytesseract库)

《Python验证码识别方式(使用pytesseract库)》:本文主要介绍Python验证码识别方式(使用pytesseract库),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全... 目录1、安装Tesseract-OCR2、在python中使用3、本地图片识别4、结合playwrigh

C++ HTTP框架推荐(特点及优势)

《C++HTTP框架推荐(特点及优势)》:本文主要介绍C++HTTP框架推荐的相关资料,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. Crow2. Drogon3. Pistache4. cpp-httplib5. Beast (Boos

SpringBoot基础框架详解

《SpringBoot基础框架详解》SpringBoot开发目的是为了简化Spring应用的创建、运行、调试和部署等,使用SpringBoot可以不用或者只需要很少的Spring配置就可以让企业项目快... 目录SpringBoot基础 – 框架介绍1.SpringBoot介绍1.1 概述1.2 核心功能2

Spring框架中@Lazy延迟加载原理和使用详解

《Spring框架中@Lazy延迟加载原理和使用详解》:本文主要介绍Spring框架中@Lazy延迟加载原理和使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、@Lazy延迟加载原理1.延迟加载原理1.1 @Lazy三种配置方法1.2 @Component

springboot security验证码的登录实例

《springbootsecurity验证码的登录实例》:本文主要介绍springbootsecurity验证码的登录实例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录前言代码示例引入依赖定义验证码生成器定义获取验证码及认证接口测试获取验证码登录总结前言在spring

Python Dash框架在数据可视化仪表板中的应用与实践记录

《PythonDash框架在数据可视化仪表板中的应用与实践记录》Python的PlotlyDash库提供了一种简便且强大的方式来构建和展示互动式数据仪表板,本篇文章将深入探讨如何使用Dash设计一... 目录python Dash框架在数据可视化仪表板中的应用与实践1. 什么是Plotly Dash?1.1