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

2022-04-15 0 551

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

登录方法,验证

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');
        }
      }
    }
}

表单

<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类,要与表名同名

<?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相关内容感兴趣的读者可查看本站专题

免责声明:
1、本网站所有发布的源码、软件和资料均为收集各大资源网站整理而来;仅限用于学习和研究目的,您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。 不得使用于非法商业用途,不得违反国家法律。否则后果自负!

2、本站信息来自网络,版权争议与本站无关。一切关于该资源商业行为与www.niceym.com无关。
如果您喜欢该程序,请支持正版源码、软件,购买注册,得到更好的正版服务。
如有侵犯你版权的,请邮件与我们联系处理(邮箱:skknet@qq.com),本站将立即改正。

NICE源码网 PHP编程 TP5框架简单登录功能实现方法示例 https://www.niceym.com/13711.html