配置 config.php
‘DB_HOST’ =>'localhost',
‘DB_USER’ => 'root',//用户名
‘DB_PWD’ => '', //密码
‘DB_NAME’ =>'', //名称
‘DB_PREFIX’ => //前缀
$db = M('user');
$user = $db->where(array('username' => I('username')))->find();
p($user)
if(!$user || $user['password'] == I('password','','MD5')){
$htis->error('账户或密码错误');
}
更新
$data = array(
'id'=>$user['id'],
'logintime'=>time(),
'loginip' =>get_client_ip()
);
$db->save($data);
写进SESSION
session('uid',$user['id']);
session('username',$user['username']);
session('logintime',date('Y-m-d H:i:s'),$user['logintime']));
session('loginip',$user['loginip']);