控制器:
<?php
//会员中心
class MemberAction extends CommonAction {
public function login(){
$this->display();
}
public function login_check(){
if(IS_POST){
$email= trim($_POST['email']);
$password= md5(trim($_POST['password']));
$remember= trim($_POST['remember']);
$where['email']=$email;
$where['password']=$password;
$where['disable']=1;
$rs = M("Member")->where($where)->find();
if($rs){
//修改上次登录ip、时间
$data1['lastlogip']=$rs['nowlogip'];
$data1['lastlogtime']=$rs['nowlogtime'];
M("Member")->where("id=$rs[id]")->save($data1);
//修改本次登录ip、时间
$data2['nowlogip']=get_client_ip();
$data2['nowlogtime']=time();
M("Member")->where("id=$rs[id]")->save($data2);
$_SESSION['qtuname']=$email;
$_SESSION['id']=$rs['id'];
if($remember){
cookie('remember_password',trim($_POST['password']),3600*24*30); // 指定密码保存一个月
cookie('remember_email',trim($_POST['email']),3600*24*30);
}
M("Member")->execute("update `tp_member` set `loginnum`=`loginnum`+1 where id='".$rs[id]."'"); //登录次数加1
$this->success("登录成功",U("Index/index"));
// $this->redirect("Index/index");
}else{
$this->error("用户名或密码错误");
}
}
}
public function registered(){
if(IS_POST){
$Email=trim($_POST['email']);
$PassWord=md5(trim($_POST['password']));
$m = M("Member");
$UserObj = $m->where(array('email'=>$Email))->find();
if(is_array($UserObj)){
$this->error('用户名已存在!');
}else{
if($m->create()){
$m->username=$Email;
$m->password=$PassWord;
$m->disable=1;
$m->addip=get_client_ip();
$m->addtime=time();
$m->updatetime=time();
if($m->add()){
$this->success("注册成功!即将返回登录","__APP__/Member/login");
}
}else{
$this->error('注册失败!');
}
}
}else{
$this->display();
}
}
public function logout(){
// $_SESSION=array();
// if(isset($_COOKIE[session_name()])){
// setcookie(session_name(),'',time()-1,