laravel 添加验证码
1、 安装依赖 composer require gregwar/captcha
2、使用
use Gregwar\Captcha\CaptchaBuilder;
use DB;
use Request;
use Session; //生成验证码
public function captcha() {
//生成验证码图片的Builder对象,配置相应属性
$builder = new CaptchaBuilder;
//可以设置图片宽高及字体
$builder->build($width = 250, $height = 70, $font = null);
//获取验证码的内容
$phrase = $builder->getPhrase();
//把内容存入session
Session::flash('milkcaptcha', $phrase);
//生成图片
header("Cache-Control: no-cache, must-revalidate");
header('Content-Type: image/jpeg');
$builder->output();
} /**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create_mes(Request $request)
{
extract($request::all());
if (Session::get('milkcaptcha') == $code) {
//用户输入验证码正确
return \Response::json(array('code' => 0, 'info' => 'ok'));
} else {
//用户输入验证码错误
return \Response::json(array('code' => 2, 'info' => 'erro'));
} $res = DB::insert('insert message (content,username,createtime,contract) values (?,?,now(),?)',
[$content, $username, $contract]);
return \Response::json(array('code' => 0, 'info' => 'ok'));
}
3、vue 端 , 提交失败或者成功都重新获取验证码
<img @click="changeCode()" class="vCode" ref="vCImg" :src="baseURL+'captcha'" />
changeCode() {
let img = this.$refs.vCImg
img.src = baseURL+'captcha?'+new Date().getTime();
}
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
bolosev.create_mes(this.message).then(res=>{
if (res.code==0){
this.$message.success("留言成功")
this.changeCode()
this.resetForm(formName)
}
else if (res.code==2)
{
this.$message.error("验证码有误")
this.changeCode()
}else
this.$message.error("留言失败")
})
} else {
console.log('error submit!!');
return false;
}
});
},
laravel 添加验证码的更多相关文章
- TODO:Laravel增加验证码
TODO:Laravel增加验证码1. 先聊聊验证码是什么,有什么作用?验证码(CAPTCHA)是"Completely Automated Public Turing test to te ...
- asp.net添加验证码
1.新建一个aspx页面生成验证码图像 using System; using System.Data; using System.Configuration; using System.Collec ...
- PHPCMS v9 自定义表单添加验证码验证
1. 在 \phpcms\templates\default\formguide\show.html 中添加验证码显示 <input type="text" id=" ...
- Angular企业级开发(9)-前后端分离之后添加验证码
1.背景介绍 团队开发的项目,前端基于Bootstrap+AngularJS,后端Spring MVC以RESTful接口给前端调用.开发和部署都是前后端分离.项目简单部署图如下,因为后台同时采用微服 ...
- PHPCMS v9 自定义表单添加验证码
1. 在 \phpcms\templates\default\formguide\show.html 中添加验证码显示 <input type="text" id=&quo ...
- cas4.2.4 登添加验证码
看了很多添加验证码的博文,唯独没有4.24的 重点看第3条,其余的和别人博文大致相同 1.首先在cas工程的web.xml增加验证码功能的支持 <!-- 验证码功能 --> &l ...
- [phpcms v9]自定义表单添加验证码验证功能
修改 \phpcms\templates\default\formguide\show.html 中添加验证码显示 <input type="text" id=" ...
- 【转】PHPCMS v9 自定义表单添加验证码验证
1. 在 \phpcms\templates\default\formguide\show.html 中添加验证码显示 <input type="text" id=&quo ...
- C# DateTime的11种构造函数 [Abp 源码分析]十五、自动审计记录 .Net 登陆的时候添加验证码 使用Topshelf开发Windows服务、记录日志 日常杂记——C#验证码 c#_生成图片式验证码 C# 利用SharpZipLib生成压缩包 Sql2012如何将远程服务器数据库及表、表结构、表数据导入本地数据库
C# DateTime的11种构造函数 别的也不多说没直接贴代码 using System; using System.Collections.Generic; using System.Glob ...
随机推荐
- Django 的逆向解析url--reverse(转)
https://www.cnblogs.com/zhenfei/p/6368955.html Django中提供了一个关于URL的映射的解决方案,你可以做两个方向的使用: 1.有客户端的浏览器发起一个 ...
- leetcode-algorithms-22 Generate Parentheses
leetcode-algorithms-22 Generate Parentheses Given n pairs of parentheses, write a function to genera ...
- leetcode-algorithms-18 4Sum
leetcode-algorithms-18 4Sum Given an array nums of n integers and an integer target, are there eleme ...
- vscode代码保存时自动格式化成ESLint风格(支持VUE)
一.问题 vscode的默认的代码格式化ctrl+shift+f 无法通过eslint的代码风格检查是一个非常蛋疼的问题 同样在进行vue项目开发的时候,使用eslint代码风格检查是没啥问题的,但是 ...
- openssl安装/更新教程(CentOS)
1.下载openssl 下载链接:https://www.openssl.org/source/snapshot/ 里边是当前仍支持版本的快照:同版本不同日期内容可能不同的,所以下载一般下对应版本的最 ...
- Kali安装教程(VMWare)
1.下载镜像及相关 1.1下载镜像文件 下载链接:https://www.kali.org/downloads/ 选择自己需要的版本下载,根据经验先下载种子文件(torrent)再用迅雷下载网速是最有 ...
- u-boot的内存分布
cpu会自动从NAND flash 中读取前4KB的数据放置在片内SRAM里(s3c2440是soc),同时把这段片内SRAM映射到nGCS0片选的空间(即0x00000000).cpu是从0x000 ...
- angular 路由项目例子
angular 路由是我在工作中体验非常便捷的一点, 这是详细的API ,查看API 可以了解很多东西, https://github.com/angular-ui/ui-router/wiki/Qu ...
- js两种打开新窗口
1.超链接<a href="http://www.jb51.net" title="脚本之家">Welcome</a> 等效于js代码 ...
- bzoj1045
题解: 随便推一下公式 然后发现是中位数 代码: #include<bits/stdc++.h> using namespace std; ],n; long long sum; int ...