首页 技术 正文
技术 2022年11月14日
0 收藏 636 点赞 2,305 浏览 2273 个字

1、下载

composer require topthink/think-captcha 1.*
// composer 下载
//过程
D:\PHP\phpstudy_pro\WWW\1906A\pyg>composer require topthink/think-captcha 1.*
./composer.json has been updated
Running composer update topthink/think-captcha
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
- Locking topthink/think-captcha (v1.0.8)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Downloading topthink/think-captcha (v1.0.8)
- Installing topthink/think-captcha (v1.0.8): Extracting archive
Generating autoload files

//下载完成后

2.验证码包的位置:

3. 修改view/login/login.html 验证码图片img标签src属性

<!DOCTYPE html>
{__NOLAYOUT__}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>登录</title>
<link rel="stylesheet" href="__STATIC__/admin/css/login.css" rel="external nofollow" >
</head>
<body>
<form action="/goods/login/save" method="post">
<div class="login">
<div class="center">
<h1>Login</h1>
<div class="inputLi">
<strong>账户</strong>
<input type="text" placeholder="账户" name="account">
</div>
<div class="inputLi">
<strong>密码</strong>
<input type="password" placeholder="密码" name="password">
</div>
<div class="inputLi">
<strong>验证码</strong>
<input type="text" placeholder="" name="cord">
<img src="{:captcha_src()}" name="img" onclick="this.src='{:captcha_src()}'"
>
</div>
<div class="inputLi">
<button type="submit">登录</button>
</div>
</div>
</div>
</form>
</body>
</html>

4.控制器验证登录,记录session

  public function save(Request $request)
{
//
$params = $request->param();
//验证参数、非空
$rule = [
'account' => 'require',
'password' => 'require',
'cord' => 'require',
];
$tips = [
'account.require' => '账号不可以为空',
'password.require' => '密码不可以为空',
'cord.require' => '验证码不可以为空',
];
$validate = new Validate($rule, $tips);
$result = $validate->check($params);
if (!$result) {
$this->error($validate->getError());
}
//数据库验证参数
$data = GoodModel::login($params);
//验证账号
if ($params['account'] != $data['name']) {
$this->error('账号错误', '/goods/login/create');
}
//验证密码
if (md5($params['password']) != md5($data['password'])) {
$this->error('密码错误', '/goods/login/create');
}
//验证码进行验证
if (!captcha_check($params['cord'])) {
$this->error('验证码输入错误', '/goods/login/create');
};
if ($data){
//记录session
session('name',$data['name']);
$this->success('登录成功', '/goods/goods/index');
} }
上一篇: qt(二)
下一篇: 小程序WXS 模块
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,491
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,492
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,293