亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

ThinkPHP實(shí)現(xiàn)登錄退出功能

 更新時(shí)間:2017年06月29日 17:06:31   作者:SYsunyi  
這篇文章主要為大家詳細(xì)介紹了ThinkPHP實(shí)現(xiàn)登錄退出功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了ThinkPHP實(shí)現(xiàn)登錄退出功能的具體代碼,供大家參考,具體內(nèi)容如下

<?php 
/**
 * 用戶登陸與退出
 * 注冊(cè)成功后,將頁面跳轉(zhuǎn)到login登陸頁面
 * 當(dāng)數(shù)據(jù)提交到登陸頁面后,必須先執(zhí)行驗(yàn)證碼驗(yàn)證通過再執(zhí)行登陸操作
 */
public function checkyzm($yzm){
 $verify=new \Think\Verify();//實(shí)例化TP自帶的Verify方法
 if($verify->check($yzm)){//調(diào)用check方法
  return true;
 }else{
  echo '驗(yàn)證碼錯(cuò)誤';
  exit();
 }
}

public function login(){
 if(!IS_POST){
  $this->display();
 }else{
  //若驗(yàn)證碼驗(yàn)證通過
  if($this->checkyzm(I('post.yzm'))){
   $username=I('post.username');
   $user=D( ' user ' )->where(" username='$username' ")->find();
   //post過來的password拼接鹽md5后密碼=數(shù)據(jù)庫的密碼,則通過
   if(md5( I( ' post.password ' ) . $user[ ' salt ' ])===$user['password']{
    cookie('username' , $userp[ ' username ' ]);//寫入cookie
    $this->redirect('/');//跳轉(zhuǎn)到首頁
   }else{
    echo '用戶名或密碼不對(duì)';
   }
  }
 }
}


/**V層
 * 退出登陸
 * 讀取cookie $Think.cookie
 */
//若沒有cookie數(shù)據(jù)
您好歡迎觀臨
<if condition="$Think.cookie.username eq null">
<a href="{:U('Home/User/login')}" rel="external nofollow" rel="external nofollow" style="color:#50884b">登陸</a> |
<a href="{:U('Home/User/reg')}" rel="external nofollow" style="color:#50884b">免費(fèi)注冊(cè)</a> |
<else />
{$Think.cookie.username}|
<<a href="{:U('Home/User/login')}" rel="external nofollow" rel="external nofollow" style="color:#50884b">退出</a>
 </if>


 /**
 * 退出方法
 * 1,cookie設(shè)為null,刪除cookie
 * 2. 跳轉(zhuǎn)到首頁
 */
 public function logout(){
  cookie('username' , null);
  $this->redirect('/');
 }

 ?>}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論