Simple Analysis of ucenter member synchronous login communication principle, ucenter communication principle

Source: Internet
Author: User

Simple Analysis of ucenter member synchronous login communication principle, 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.

Application logging. php ------> client. php ------> 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

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.

<Script type = "text/javascript" src = "http://rayibeauty.ck101.com/api/uc.php? Time = 1408327309 & code = bc6bFLa6WH343nin2GAn % messages % 2FfQ1GK6FS % 2BqJqi2AxVG2Oq1pD9c1wZy % messages "reload =" 1 "> </script>

<Script type = "text/javascript" src = "http://kibeauty.ibeauty.tw/api/uc.php? Time = 1408327309 & code = 206 flCqeb % 2 Faft % found % 2BkebI7uLm58atk8Ex4sKBj % 2 ffdk%2f8z "reload =" 1 "> </script>

Similar js Code is sent to each application that enables synchronous login, and then the callback file uc for each application that enables synchronous login. after receiving the code, php decrypts the code. After decryption, you can write the code by yourself. This uc. php callback File Code does not have to be written in their format. You can also write your own code.

In fact, the working principle of UC is very simple, that is, after an application logs in, the background polls and sends the callback file to the application for Synchronous login. After the callback file receives the user ID, generate a cookie or session and enter login mode.


Ecshop + discuz UCenter integration shows that the communication is successful, but member synchronization is not supported.

Check whether you are allowed to synchronize members and log on to the uncenter background. Application Management-ecshop configuration!

When the UCenter implements synchronous login, you need to read data from the database to determine whether the login is successful?

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 ------> client. php ------> Ucenter ------> api/uc. php In the application

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. After learning about the Ucenter synchronization principle, it is much easier to log on synchronously or develop some interfaces with the UCenter.

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.