thinkPHP实现的验证码登录功能示例

2025-05-29 0 45

本文实例讲述了thinkPHP实现的验证码登录功能。分享给大家供大家参考,具体如下:

使用thinkphp自带的验证,实现登录页面的账号密码+验证码的验证

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41
<?php

namespace Admin\\Controller;

use Think\\Controller;

use Think\\Verify;

class LoginController extends Controller{

public function login(){

if($_POST){

$obj = new Verify();

if($obj->check(I('post.yanzhengma','','trim'))){

// 注释部分为另外一种从数据库中验证密码的方法

// $data['name'] = I('post.user_name');

// $data['psd'] = I('post.password');

// $row = M('user')->where($data)->find();

$name = I('post.user_name');

$psd = I('post.password');

$str = 'name ="'.$name. '" and tel = "'.$psd.'"';

var_dump($str);

$row = M('user')->where($str)->find();

if($row)

$this->redirect("Index/index");

else

$this->redirect('login','',1,'用户名或密码错误');

}

else{

$this->redirect('login','',1,'验证码错误');

}

}

$this->display();

}

public function verifyImg(){

//设置验证码的宽高字体大小以及验证码的个数,设计其他的参照Think\\Verify里面的设置

$config=array(

'imageW' => 150,

'imageH' => 40,

'fontSize' => 20,

'length' => 4

);

$obj = new \\Think\\Verify($config);

$obj->entry();

}

}

表单部分

?

1

2

3

4

5

6

7

8

9

10

11

12
<form action="login" method="post">

<table valign="top" width="50%">

<tr><td colspan="2"><h4 style="letter-spacing:1px;font-size:16px;">RainMan 网站管理后台</h4></td></tr>

<tr><td>管理员:</td><td><input type="text" name="user_name" value="" /></td></tr>

<tr><td>密&nbsp;&nbsp;&nbsp;&nbsp;码:</td><td><input type="password" name="password" value="" /></td></tr>

<tr><td>验证码:</td>

<td><input type="text" name="yanzhengma" value="" style="width:80px;"/></td>

<td><img src="__URL__/verifyImg" onclick="this.src='__URL__/verifyImg/'+Math.random()" alt=""/></td>

</tr>

<tr class="bt" align="center"><td>&nbsp;<input type="submit" value="登陆" /></td><td>&nbsp;<input type="reset" value="重填" /></td></tr>

</table>

</form>

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

原文链接:http://blog.csdn.net/qq_22793991/article/details/53674197

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 thinkPHP实现的验证码登录功能示例 https://www.kuaiidc.com/92917.html

相关文章

发表评论
暂无评论