TP5框架简单登录功能实现方法示例

吾爱主题 阅读:125 2021-09-15 16:38:00 评论:0

本文实例讲述了TP5框架简单登录功能实现方法。分享给大家供大家参考,具体如下:

登录方法,验证

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 public function login() {      if (request()->isGet()){        return view( 'login' );      } elseif (request()->isPost()){        $model = new InfoModel();        $name = input( 'name' ); //获取表单提交的姓名        $pwd = input( 'password' ); //获取表单提交的密码        if ( $model ->LoginVerify( $name , $pwd )){          $verify = input( 'code' ); //获取验证码的值          $cap = new Captcha(); //实例化验证码类          if ( $cap ->check( $verify )){            $this ->success( '登录成功' , 'admin/ShowIndex' ); //登录成功跳转首页            /*echo '登录成功';*/          } else {            $this ->error( '验证码错误' , 'admin/admin/login' );          }        }      } }

表单

?
1 2 3 4 5 6 7 8 9 10 11 12 < div class = "form-group" >      < div class = "field field-icon-right" >        < input type = "password" class = "input input-big" name = "password" placeholder = "登录密码" data-validate = "required:请填写密码" />        < span class = "icon icon-key margin-small" ></ span >      </ div >    </ div >    < div class = "form-group" >      < div class = "field" >        < input type = "text" class = "input input-big" name = "code" placeholder = "填写右侧的验证码" data-validate = "required:请填写右侧的验证码" />        < img src = "{:captcha_src()}" alt = "" width = "150" height = "32" class = "passcode" style = "height:43px;cursor:pointer;" ο nclick = "this.src=this.src+'?'" >      </ div > </ div >

model类,要与表名同名

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <?php namespace app\admin\model; use think\Model; class Info extends Model { #登录验证    public function LoginVerify( $name , $pwd )    {      //$re = $this->where(["username =>'$name',pwd=>'$pwd'"])->find();      $re = $this ->where( "username='$name' and pwd='$pwd'" )->find();      if ( $re ){        return $re ;      } else {        return null;      }    } }

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

原文链接:https://blog.csdn.net/lingluo110700/article/details/82353876

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容