Explanation of using ucenter to realize multi site synchronous login

  • 2021-12-04 09:35:32
  • OfStack

Web development often requires the realization of multi-site synchronous login. For PHP development, we can use ucenter to realize the functions of multiple sites logging in and exiting at the same time and users synchronizing. Let's take a look at how ucenter realizes synchronous login.

First of all, each site should introduce a client such as uc_client, Take landing as an example, When you log in, you will first call an external function. uc_user_login under uc_client/client. php checks whether the user exists, and if it is correct, continues to execute the login code to detect this user process: through what way the user is connected to uc (mysql or http post) and then uses different functions to detect the user accordingly. After the detection is completed, the local login is realized, and the code is written by itself, and then other applications are also logged in. At this time, external functions are called uc_user_synlogin The process is as follows:

Uc_user_synlogin Call uc_api_post to realize which module to do, For example, now it is the user module, and the transmitted parameter is user_id. I don't look carefully at how this is realized. In short, I send the data to uc_api, that is, index. php of your ucenter address, and attach some parameters at the same time. According to these parameters, I will read all the communicable applications inside, so that they can also log in. This is a matter for other programs.

Notify other applications mainly through ucenter, and send some data to api/uc. php under each application. These data are requested by uc. php and then execute corresponding login operations.

Let's give an example to describe the whole process under 1

1. The user xxx enters the user name and password in login. php of a 1 application. First use the uc_user_login function to uc server to verify this user and password. If it is correct, write session, write cookies, and update the login ip and login time in the application membership table. Users don't feel the process.

2. The uc server user is then notified via uc_user_synlogin that the xxx login was successful. This process may use ajax, and the user does not feel the notification process.

3. After receiving this message, uc server immediately commands his staff to send the message of xxx login, like Token Ring 1, to all other applications willing to receive this message (whether to start synchronous login in the background). It is actually uc. php with parameters accessing each application under 1, and the user does not feel this process.

4. Applications rely on uc. php under api to receive messages from uc server, and do whatever uc server says. Now, receive the command to let xxx users log in to your program, and execute it immediately. And write the session of this application, and use p3p to write cookies of the same domain or different domains. Users do not feel this process.

5. Finally, all the programs integrated with uc and xxx were successfully logged in. After the user logs in from www. ofstack. com, skipping to www. ofstack. com also shows login.

6. The application's session with uc server ends.

Summarize


Related articles: