Test Application: UCenter_1.6.0_ SC _UTF8, Discuz! X2, MLECMS
The installation methods of discuz and ucenter are well known.
After installation, log on to the ucenter and add an mlecms application, for example:
Next we will perform the following operations step by step:
Step 1: open and download the advanced folder in the UCenter_1.6.0_ SC _UTF8 folder, which is an interface file with other websites. The document in it is the API description of the interface, and the examples folder is some examples, you can also use the root scripts for reference. uc_client is an interface file.
Step 2: copy the include folder and api folder in the examples folder to the root directory of your website. The include folder contains a file named db_mysql.class.php, which is the class for connecting to the database.
Step 3: copy the uc_client folder to the root directory of your website. uc_client previously described the interface code. Now the root directory has three folders: api, include, and uc_client.
Step 4: Copy config. inc. php In the examples folder to the root directory of your website. This is the configuration file for configuring UCenter.
Step 5: Configure parameters of config. inc. php
In the mlecms application,Application ucenter
Configuration information"Copy the content in the text box below to config. inc. php, for example:
After the preceding steps are configured, your application can successfully communicate with the ucenter, for example:
Next, we will modify the logon, logout, and registration pages of mlecms to synchronize with discuz.
You need a ucenter interface development manual to facilitate your smooth implementation of the following steps. : Ucenter interface development manual
(1) We will first implement two-way synchronous login, that is, the user logs on to the mlecms and switches to discuz, which is also the logon status.
First, add the synchronous login code to the mlecms login file. We can find the member/login. php logon page of mlecms:
(Note: To use the synchronous interface function of UC, you must first reference the two files: config. Inc. php and uc_client/client. php)
if(!empty($_POST['username']) && !empty($_POST['password'])){$captcha = true;if($mle['login_captcha']){$img = new captcha();$captcha = $img->check($_POST['captcha']);}if($captcha === true){$flag = member::login($_POST['username'],$_POST['password'],numeric($expire));switch($flag){case 0 : msgbox($language['page']['not_exist'],$config['url'].misc::url('login')); break; case -1 : msgbox($language['page']['password_error'],$config['url'].misc::url('login')); break; case -2 : msgbox($language['page']['mail_activation'],$config['url'].misc::url('login')); break; case -3 : msgbox($language['page']['manage_activation'],$config['url'].misc::url('login')); break; case -4 : msgbox($language['page']['refused_login'],$config['url'].misc::url('login')); break; case -5 : msgbox($language['page']['unknown_error'],$config['url'].misc::url('login')); break; default :msgbox('',$config['url'].'member/');break;}} else { msgbox($language['page']['captcha_error'],$config['url'].misc::url('login'));}}
According to the ucenter interface development manual and the login_db.php example in the ucenter_1.6.0_ SC _utf8 folder, add the synchronous login code as follows:
If (! Empty ($ _ post ['username']) &! Empty ($ _ post ['Password']) {$ CAPTCHA = true; if ($ MLE ['login _ CAPTCHA ']) {$ IMG = new CAPTCHA (); $ CAPTCHA = $ IMG-> check ($ _ post ['captcha ']);} if ($ CAPTCHA = true) {$ flag = Member :: login ($ _ post ['username'], $ _ post ['Password'], numeric ($ expire); Switch ($ flag) {Case 0: msgbox ($ language ['page'] ['not _ exist'], $ config ['url']. misc: URL ('login'); break; Case-1: msgbox ($ language ['page'] ['password _ error'], $ config ['ur L']. misc: URL ('login'); break; Case-2: msgbox ($ language ['page'] ['mail _ activation'], $ config ['url']. misc: URL ('login'); break; Case-3: msgbox ($ language ['page'] ['Manage _ activation'], $ config ['url']. misc: URL ('login'); break; Case-4: msgbox ($ language ['page'] ['refused _ login'], $ config ['url']. misc: URL ('login'); break; Case-5: msgbox ($ language ['page'] ['unknown _ error'], $ config ['url']. misc: URL ('Login'); break; default: // you can use the API to determine whether the Logon account is correct. The returned value is an array list ($ uid, $ username, $ password, $ email) = uc_user_login ($ _ post ['username'], $ _ post ['Password']); setcookie ('auth', '',-86400 ); if ($ uid> 0) {/* If (! $ Db-> result_first ("select count (*) from {$ tablepre} members where uid = '$ uid'") {// determine whether a user exists in the User table, if this parameter does not exist, go to the activation page $ auth = rawurlencode (uc_authcode ("$ USERNAME \ t ". time (), 'encoding'); echo 'You need to activate this account to enter this application <br> <a href = "'. $ _ server ['php _ Self ']. '? Example = register & Action = Activation & auth = '. $ Auth. '"> continue </a>'; exit;} * // the user logs in successfully. Set the cookie and use the uc_authcode function for encryption, the user uses his function setcookie ('auth ', uc_authcode ($ uid. "\ t ". $ username, 'encoding'); // generate the synchronous logon code $ ucsynlogin = uc_user_synlogin ($ UID); echo 'logon successful '. $ ucsynlogin. '<br> <a href = "'. $ _ server ['php _ Self ']. '"> continue </a>'; msgbox ('', $ config ['url']. 'Member/');} elseif ($ uid =-1) {msgbox ('user does not exist or is delete', $ config ['url']. misc: URL ('login');} elseif ($ uid =-2) {msgbox ('wrong password ', $ config ['url']. misc: URL ('login');} else {msgbox ('undefined ', $ config ['url']. misc: URL ('login');} break;} else {msgbox ($ language ['page'] ['captcha _ error'], $ config ['url']. misc: URL ('login '));}}
Test: register a user named test in discuz. Because the synchronization between discuz and ucenter has been written, this user will also be in the ucenter, register a user named test in mlecms, and use this user in mlecms to log on successfully. Go to the discuz page and the user is logged on.
Next, modify the mlecms API/UC. php file, modify the synlogin function, and add the synchronous login code:
Function synlogin ($ get, $ post) {$ uid = $ get ['uid']; $ username = $ get ['username']; // $ Pwd = $ get ['Password']; global $ _ g; If (! Api_synlogin) {return api_return_forbidden;} header ('p3p: Cp = "Cura ADMA Deva psao psdo our bus uni pur int DEM sta pre com nav OTC Noi DSP cor "'); header ("Location :.. /member/login. PHP? Username = $ username & uid = $ uid "); // synchronous logon}
Modify mlecms/INC/class/member. Class. php and add a new synclogin function to log on using the username and user ID:
public static function synclogin($username,$uid,$expire = 0){global $db,$gmt_time;$username = trim(preg_replace('/[\'\"\\\\\/]/','',$username));$uid = trim(preg_replace('/[\'\"\\\\\/]/','',$uid));$row = $db->query("SELECT a.*,b.`rankname` FROM `{$db->prefix}members` a,`{$db->prefix}rank` b WHERE (a.`username` = '{$username}' || a.`email` = '{$username}') && a.`level` = b.`id` && a.`id` = '{$uid}' LIMIT 1",1);if(isset($row['username'])){//if(md5(md5($password).md5($row['encryption'])) == $row['password']){ if($row['audit'] == 0 && $row['effective']){$expire != 0 && $expire = $gmt_time + ($expire * 3600); setcookie('mlecms_user_login',encryption('mlecms','ENCOD',WEBKEY),$expire,'/'); setcookie('mlecms_user_id',encryption($row['id'],'ENCOD',WEBKEY),$expire,'/'); setcookie('mlecms_user_auth',encryption($row['id'].$row['password'].$row['encryption'],'ENCOD',WEBKEY),$expire,'/'); setcookie('mlecms_user_name',$row['username'],$expire,'/'); setcookie('mlecms_user_email',$row['email'],$expire,'/'); setcookie('mlecms_user_frequency',$row['frequency'] + 1,$expire,'/'); $rankname = explode(',',$row['rankname']);$rankname = $rankname[LANG - 1];setcookie('mlecms_user_rankname',$rankname ,$expire,'/'); setcookie('mlecms_user_money',$row['money'],$expire,'/'); setcookie('mlecms_user_usemoney',$row['usemoney'],$expire,'/'); setcookie('mlecms_user_scores',$row['scores'],$expire,'/'); $ip = explode(',',$row['loginip']);$ip = $ip[1].','.get_ip();$tm = explode(',',$row['logintime']);$last_time = is_numeric($tm[1]) ? $tm[1] : numeric($tm[0]); $tm = $tm[1].','.$gmt_time;$integral = numeric($row['scores']);if($last_time && $last_time < ($gmt_time - 43200)){$member_config = self::get_config();$integral += $member_config['login_scores'];}$level = self::get_upgrade_rank($row['level'],$integral,$row['money']);$db->execute("UPDATE `{$db->prefix}members` SET `loginip` = '{$ip}',`logintime` = '{$tm}',`frequency` = (`frequency`+1),`scores` = '{$integral}',`level` = '{$level}' WHERE `id` = '{$row['id']}';");return is_numeric($row['id']) ? $row['id'] : -5; } elseif ($row['audit'] == 1){return -2;} elseif ($row['audit'] == 2){return -3;} elseif ($row['effective'] == 0){return -4;} else {return -5;}//} else {//return -1; //}} else {return 0; }}
Modify the member/login. PHP page and add the get login code:
if(!empty($_GET['username'])&&!empty($_GET['uid'])){$syn_flag = member::synclogin($_GET['username'],$_GET['uid'],numeric($expire));switch($syn_flag){case 0 : msgbox($language['page']['not_exist'],$config['url'].misc::url('login')); break; case -1 : msgbox($language['page']['password_error'],$config['url'].misc::url('login')); break; case -2 : msgbox($language['page']['mail_activation'],$config['url'].misc::url('login')); break; case -3 : msgbox($language['page']['manage_activation'],$config['url'].misc::url('login')); break; case -4 : msgbox($language['page']['refused_login'],$config['url'].misc::url('login')); break; case -5 : msgbox($language['page']['unknown_error'],$config['url'].misc::url('login')); break; default : msgbox('',$config['url'].'member/'); break;}}
Test: log on to the discuz using the test user and go to the mlecms page. The user is also logged on and synchronized successfully.
(Note: To achieve this step smoothly, you need to go to the discuz background-> interface settings-> globally remove the check box of the floating window for logon and registration, I didn't succeed in the morning because I didn't remove this check box. Don't take a detour)
Now, two-way synchronous login has been basically implemented.
(2) achieve two-way synchronous logout, that is, the user logs out in mlecms, and the log out status is also transferred to the Forum.
Login. php login code in mlecms:
$action == 'logout' && member::logout() && msgbox('',$config['url']);
Add the synchronous logout code:
If ($ action = 'logout' & Member: Logout () {echo uc_user_synlogout (); // synchronously exit msgbox ('', $ config ['url']);}
Test: log out of mlecms and go to the discuz page. The user is logged out, and the log out is synchronized.
Next, modify the synlogout function in API/UC. php and add the logout code:
Function synlogout ($ get, $ post) {If (! Api_synlogout) {return api_return_forbidden;} // note synchronous logout API header ('p3p: CP = "Cura ADMA Deva psao psdo our bus uni pur int DEM sta pre com nav OTC Noi DSP cor" '); header ("Location :.. /member/login. PHP? Action = logout "); // log out synchronously}
Test: log out of the test user in discuz and go to the mlecms page. The user is logged out. The log out is synchronized.
The first part is written here first. It may not be too long ~