[User verification] this train of thought verifies whether the user has logged on to the system with any vulnerabilities or problems.

Source: Internet
Author: User
[User verification] this train of thought is used to verify whether a user has logged on to the website for any vulnerabilities or problems. This post was last posted by default7 from 2014-05-2513: 31: 32 editing considers the server to minimize SQL queries. SESSION becomes invalid if the browser is closed. Therefore, the COOKIE is used, and the following method is used to check whether a user is logged on. The code is as follows: ** & nbsp; * & nbsp [user verification] The idea is to verify whether the user has logged on to the system with any vulnerabilities or problems.

This post was last edited by default7 at 13:31:32

The server can minimize SQL queries.
SESSION becomes invalid if the browser is closed. Therefore, the COOKIE is used, and the following method is used to check whether a user is logged on.

The code is as follows:

/**
* Initialization, user COOKIE data verification by default7 # zbphp.com
*/
Public function authCheck ()
{
If (cookie ('uid ')){
$ Uid = cookie ('uid ');
$ Umd5 = cookie ('umd5 ');
$ Udata = cookie ('udata ');
If (isUid ($ uid) & isMd5 ($ umd5) & $ udata & ($ strDecode = authcode ($ udata, 'decode '))
& Md5 ($ strDecode) ==$ umd5 & ($ data = json_decode ($ strDecode) & $ data ['uid'] = $ uid ){

// Check the SQL check every 60 s
If ($ this-> time-$ data ['lastactive']> self: INTERVAL ){
If ($ rsUser = M ('member')-> where ("mid = '$ uid'")-> getField ('mid, uname, pwd, vip, viptime1, viptime2, lastactive, isfbd '))
& Strtolower ($ rsUser ['uname']) = strtolower ($ data ['uname'])
& Strtolower ($ rsUser ['email ']) = strtolower ($ data ['email'])
& Md5 ($ rsUser ['pwd']. $ data ['Salt']) = $ data ['upwd ']
){

If ($ rsUser ['isfbd'] ='t '){
$ This-> error ('Your account has been banned. please contact the administrator! ');
$ This-> resetUser ();
Return;
}

// Update the last online time
M ('member')-> setField ('lastactive', $ this-> time );

// Regenerate the encryption key
$ Data ['Salt'] = uniqid ();
$ Data ['upwd '] = md5 ($ rsUser ['pwd']. $ data ['Salt']);

} Else {

$ This-> error ('account information (email address or password) has changed. please log on again! ', '', U ('Member/Index/login? F = './index. php/Article ));
$ This-> resetUser ();
Return;

}
}

$ Data ['lastactive'] = $ this-> time;

$ This-> UserData = $ data;

$ StrEncode = json_encode ($ data );

// Configure the COOKIE to expire in 10 days by default
Cookie ('uid', $ data ['uid']);
Cookie ('umd5 ', md5 ($ strEncode ));
Cookie ('udata', authcode ($ strEncode, 'encoding '));

Return;
}

$ This-> resetUser ();
}
}

/**
* Cancel all SESSION
*
* @ Return bool
*/
Public function resetUser ()

Related Article

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.