Skip to content

Instantly share code, notes, and snippets.

@no13bus
Created March 6, 2014 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save no13bus/9389605 to your computer and use it in GitHub Desktop.
Save no13bus/9389605 to your computer and use it in GitHub Desktop.
public function login()
{
if(!IS_POST) $this->redirect('index',array('errormsg' => '非法请求'));
$email = I('email');
$last_login = date(time(),"Y-m-d,H:i:s");
$password = I('password','','md5');
/////find只会找到一条记录 这个是和select不同的地方 这找到的是一个集合
$user = M('user')->where(array('email' => $email))->find();
if (!$user || $user['password']!= $password) {
$this->error('用户名不存在或者密码不正确');
}
session('username',$user['username']);
session('email',$user['email']);
session('uid',$user['uid']);
//////cookie
$auto = $user['uid'] . '|' . $user['username'];
cookie('auto',$auto,3600);
$data = array(
'uid' => $user['uid'],
'username' => $user['username'],
'email' => $user['email'],
'last_login' => date("Y-m-d H:i:s",time()),
);
$user = M('user')->data($data)->save();///uid important
$this->redirect('Index/Index/index');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment