[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 ()