Refer to my login process below
Define processing background Login submission data
Public Function login () {
if (!is_post) Halt (' page does not exist ');
$username =i ("username");
$pwd =i ("Password", "', ' MD5 ');
P ($pwd);d ie;
1. Check if the user exists in the database
$user =m (' user ')->where (Array (' username ' = "$username"))->find ();
If the user in the database does not exist or exists but the password is incorrect, an error is found.
if (! $user | | $user [' password ']!= $pwd) {
$this->error ("User name or password is wrong! ");
}
If the above conditions are true, update the following data after each login
$data =array (
' id ' = $user [' id '],
' Sign ' = $user [' sign '],
' SHENFZ ' = $user [' SHENFZ '],
' Tel ' = $user [' Tel '],
' Weixin ' = $user [' Weixin '],
' QQ ' = $user [' QQ '],
' Logintime ' = Time (),
' Loginip ' = Get_client_ip ()
);
Update database data
M (' user ')->where (array (' id ' = = $user [' id ']))->save ($data);
if (In_array ($user [' ZW '],array ())} {
$role =m (' Role_user ')->where (Array (' user_id ' = = $user [' id ']))->getfield (' role_id ', true);
}else{
$role =m (' Role_user ')->where (Array (' user_id ' = ' $user [' ID ')])->getfield (' role_id ');
}
Access Login Session Data
Session (C (' User_auth_key '), $user [' id ']);
Session (username, $user [' username ']);
Session (role, $role);
Session (BM, $user [' BM ']);
Session (tel, $user [' tel ']);
Session (email, $user [' email ']);
Session (ZW, $user [' ZW ']);
Session (Logintime, $date [' logintime ']);
Session (Loginip, $user [' Loginip ']);
Jump to Background user list page after accessing session data
if ($user [' username '] = = C (' rbac_superadmin ')) {
Session (C (' Admin_auth_key '), true);
}
Import (' ORG. Util.rbac ');
Rbac::saveaccesslist ();
Insert User Action Log
$content =$_session[' username '].date ("y-m-d h:i:s", Time ()). " Logged into the log task system ";
$logs =array (
' UserID ' =>$_session[c (' User_auth_key ')],
' Operate ' =>time (),
' Content ' = $content,
' Status ' =>0
);
Access Log Operation log information
M (' Userlog ')->add ($logs);
Adjust Background home Page
$this->redirect (' Admin/index/index ');
}
thinkphp Login Detection