Ucenter application integration and single sign-on implementation code

Source: Internet
Author: User
Tags socket

has been using Kangsheng products, natural and single point of landing, the recent study of the next ucenter mechanism, in fact, it is the basic principle of a word: Set user information across domains. The following only for user login to do a more detailed description, other registration, PM and other operations in fact, similar to the principle.

User Login
Do_login.php[uchome]

$passport = Getpassport ($username, $password);

The operation here calls the Uc_client under the client.php

Uc_user_login ($username, $password);

This function also calls the

Call_user_func (uc_api_func, ' user ', ' login ', array ())

Call_user_func callback Uc_api_func, here is the Uc_api_mysql function, which calls the Uc_api_mysql function, followed by ' user ', ' login ', array () is the parameter. The essence of Uc_api_mysql is to invoke the user controller under Uc_client's controller and then execute the Onlogin method.

The method is to determine whether the user submits the information correctly, and then returns the UID of the corresponding Uc_member table.

Summarize:

1.uchome User login mainly through the uc_client operation, to determine whether the user information is correct, and eventually return the corresponding to the UC table UID, for a single point of landing.
2. Integration of their own applications can not be so complex, landing can go their own mode, just to return to the next UC table UID, for a single point of access can be.
Single point of landing
Include ' uc_client/client.php ';

Uc_user_synlogin ($uid); uc_user_synlogin

Internal is called

Uc_api_post (' user ', ' synlogin ', Array (' UID ' => $uid));

The role of the Uc_api_post function is to send data through the socket to Ucenter.

Uc_api_post calls both the Uc_api_requestdata and UC_FOPEN2 functions.

Uc_api_requestdata constructs the request data that is sent to the user center.

Uc_fopen2 remotely opens the URL, essentially calling the Uc_fopen function, opening the ucenter/index.php remotely through Fsockopen, and passing parameters, invoking the user controller to execute the Onsynlogin () method, Onsynlogin ( To read the cache, the cached file retains the basic information of each single point landing application [such as the basic information of BBS Supersite]. Then loop through JS to invoke the uc.php under the API under different applications.

Next move to the uc.php call Synlogin in each application ($get, $post)

Header (' p3p:cp= "cura ADMa DEVa Psao psdo We bus UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"];

Setcookie () to enable the cookie to be set across the domain

P3P function:

For example, there are 2 applications, a.nowamagic.net and b.nowamagic.net have a common uceter.nowamagic.net,uceter.nowamagic.net called across domains through JS a.nowamagic.net B.nowamagic.net, both scripts have the ability to set cookies, but in order to cross the domain, considering that different browsers [primarily consider IE6], you must call P3P to achieve a successful cross-domain.

Summary: In general, Ucenter One station landing principle is socket remote open ucenter, and the transmission has been logged public Uid,ucnter loop through JS invoke the API under each application, set cookies in various places, and to ensure that cookies are common is P3P processing [Note that the different application of the API script, BBS uc.php different from the Uchome uc.php].

Integration of their own applications
1. Download the Ucenter and play the Ucenter datasheet, uc_members the table's role is to store the common ID data.
2. Add uc_client and APIs under your own application, and the files under these two directories need to be changed according to the actual situation.
3. Enter the Ucenter background, add a single point landing application.
4. Add a single point of landing after the successful will appear some configuration information, in their own application add config.php, and copy configuration information, add a $database = ' mysql ';
The new version of UC Paradigm, communication is unsuccessful because the example directory of the config.inc.php less this $database = ' mysql ';
Causes the database class file to not be connected to the include/.

At this point, the basic operation has been completed, and in addition to the specific circumstances of their own application for different operations.

Other ways to apply consolidation
In fact, you can not go to the single point of landing, the whole station unified registration, login interface can, pay attention to each application of the prefix of the cookie to the same, consider cross-domain words can use jquery Jsonp, at this time of registration, login to write a set of their own, registration, landing mode and the original application of the same can be, such as the way cookies are encrypted, the scope of the cookie, and the data format that the cookie stores.

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.