thinkphp Login Detection

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.