Home  >  Article  >  Backend Development  >  Code sharing for ThinkPHP to implement login and logout functions

Code sharing for ThinkPHP to implement login and logout functions

小云云
小云云Original
2018-02-10 13:07:23908browse

This article mainly introduces the login and logout functions of ThinkPHP in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.


check($yzm)){//调用check方法
  return true;
 }else{
  echo '验证码错误';
  exit();
 }
}

public function login(){
 if(!IS_POST){
  $this->display();
 }else{
  //若验证码验证通过
  if($this->checkyzm(I('post.yzm'))){
   $username=I('post.username');
   $user=D( ' user ' )->where(" username='$username' ")->find();
   //post过来的password拼接盐md5后密码=数据库的密码,则通过
   if(md5( I( ' post.password ' ) . $user[ ' salt ' ])===$user['password']{
    cookie('username' , $userp[ ' username ' ]);//写入cookie
    $this->redirect('/');//跳转到首页
   }else{
    echo '用户名或密码不对';
   }
  }
 }
}


/**V层
 * 退出登陆
 * 读取cookie $Think.cookie
 */
//若没有cookie数据
您好欢迎观临

登陆 |
免费注册 |

{$Think.cookie.username}|
<退出
 


 /**
 * 退出方法
 * 1,cookie设为null,删除cookie
 * 2. 跳转到首页
 */
 public function logout(){
  cookie('username' , null);
  $this->redirect('/');
 }

 ?>}

Related recommendations:

How to implement the automatic login and login and exit functions of Yii2 framework

The above is the detailed content of Code sharing for ThinkPHP to implement login and logout functions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn