溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

使用TP5框架怎么實(shí)現(xiàn)一個(gè)登錄功能

發(fā)布時(shí)間:2021-04-13 16:16:46 來(lái)源:億速云 閱讀:288 作者:Leah 欄目:開(kāi)發(fā)技術(shù)

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)使用TP5框架怎么實(shí)現(xiàn)一個(gè)登錄功能,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

登錄方法,驗(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)首頁(yè)
          /*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í)顚?xiě)密碼" />
      <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="填寫(xiě)右側(cè)的驗(yàn)證碼" data-validate="required:請(qǐng)?zhí)顚?xiě)右側(cè)的驗(yàn)證碼" />
      <img src="{:captcha_src()}" alt="" width="150" height="32" class="passcode"  ο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;
    }
  }
}

上述就是小編為大家分享的使用TP5框架怎么實(shí)現(xiàn)一個(gè)登錄功能了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

tp5
AI