Ucenter communication principle analysis, ucenter communication principle. Ucenter communication principle analysis, ucenter communication principle 1. users log on to discuz and use logging. the uc_user_login function in the PHP file verifies the post data, that is, the analysis of the communication principle between username and ucenter, and the ucenter communication principle.
1. log on to discuz and use the uc_user_login function in the logging. php file to verify the post data, that is, to verify username and password.
2. if the verification succeeds, the client located in uc_client will be called. the uc_user_synlogin function in the PHP file calls uc_api_post ('user', 'synlogin', array ('uid' => $ uid) in this function )).
3. the Function then transmits data to index. php of the Ucenter. index. php accepts the transmitted data and obtains the value of model as user and action as synlogin.
4. then the Ucenter index. php calls the user in the control directory. the onsynlogin method in the php class uses the foreach loop to notify the uc application list to enable synchronous login in the form of javascript for synchronous login; that is, pass the get method to the uc under the api in each application directory. php Data.
5. uc. php receives the notification and processes the get data. in php) data is encrypted using function _ authcode (UC_KEY is used as the key by default), and cookie is set using function _ setcookie.
6. each application uses the corresponding key to decode the cookie set above to obtain user ID and other data. this value is used to determine whether the user has logged on to other applications, so that the user can log on automatically.
Logging. php of the application --> client. php in uc_client --> Ucenter --> api/uc. php in other applications.
In fact, the Ucenter implements synchronous login by using cookies. after an application successfully logs on to the Ucenter, it transmits data to the Ucenter so that the Ucenter notifies other applications to set cookies, in this way, users can automatically log on to other applications through the configured cookies.
In the general steps, first install ucenter and copy the uc_client folder to your project. then, configure several files.
Client. php is equivalent to a function library
Uc. php is equivalent to a Callback File
Config. php is the configuration file
When two of your applications are configured with synchronous login, when you log on to an application and then execute
The code is as follows:
Include './config. inc. php ';
Include './uc_client/client. php ';
$ Usernames = "kyee ";
$ Passwords = "123456 ″;
List ($ uid, $ username, $ password, $ email) = uc_user_login ($ usernames, $ passwords );
If ($ uid> 0 ){
Setcookie ("username", $ username, time () + intval (24*3600 ));
Echo uc_user_synlogin ($ uid );
Echo 'logon successful ';
} Elseif ($ uid =-1 ){
Echo 'user does not exist or is deleted ';
} Elseif ($ uid =-2 ){
Echo 'incorrect password ';
} Else {
Echo 'undefined ';
}
Uc_user_synlogin () this function means that you need to log on to all the other functions that enable synchronous login. uc will traverse all the applications that enable synchronous login in the background and then output them on the page.
The code is as follows: