Ucenter communication principle analysis, ucenter communication principle-PHP Tutorial

Source: Internet
Author: User
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:


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.