欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

TP5框架簡(jiǎn)單登錄功能實(shí)現(xiàn)方法示例

 更新時(shí)間:2019年10月31日 10:45:44   作者:珞珞珞珞珞珞珞mm  
這篇文章主要介紹了TP5框架簡(jiǎn)單登錄功能實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了thinkPHP5框架登錄功能控制器、視圖、登錄驗(yàn)證等相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了TP5框架簡(jiǎn)單登錄功能實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

登錄方法,驗(yàn)證

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'); //獲取驗(yàn)證碼的值
        $cap = new Captcha(); //實(shí)例化驗(yàn)證碼類
        if($cap->check($verify)){
          $this->success('登錄成功','admin/ShowIndex');//登錄成功跳轉(zhuǎn)首頁
          /*echo '登錄成功';*/
        }else{
          $this->error('驗(yàn)證碼錯(cuò)誤','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:請(qǐng)?zhí)顚懨艽a" />
      <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="填寫右側(cè)的驗(yàn)證碼" data-validate="required:請(qǐng)?zhí)顚懹覀?cè)的驗(yàn)證碼" />
      <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
{
#登錄驗(yàn)證
  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;
    }
  }
}

更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術(shù)總結(jié)》。

希望本文所述對(duì)大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論