Home > Backend Development > PHP Tutorial > ucenter synchronous login mechanism_PHP tutorial

ucenter synchronous login mechanism_PHP tutorial

WBOY
Release: 2016-07-13 10:31:08
Original
1090 people have browsed it

Most friends who are engaged in PHP development know that there is ucenter, which can be used to log in and log out of multiple sites at the same time, and synchronize users. Next, the author will share with you how ucenter implements synchronous login.

First of all, the site must introduce a client such as uc_client. Taking login as an example, an external function will be called first when logging in. uc_user_login under uc_client/client.php checks whether this user exists. If it is correct, continue to execute the login code. , detect this user process: according to how the user connects to uc (mysql or http post), and then use different functions to detect the user accordingly. After the detection is completed, local login is implemented, the code is written by oneself, and then other applications are also logged in. , at this time the external function uc_user_synlogin is called, the process is as follows:

Uc_user_synlogin calls uc_api_post to implement which module to use. For example, it is the user module now, and the parameter passed is user_id. I don’t look at the details of how this is implemented. In short, the data is sent to uc_api, which is your ucenter address. index.php, and also attaches some parameters. Based on these parameters, it reads all the communicable applications in it and allows them to log in. This is a matter for other programs.

Notifying other applications mainly uses ucenter to send some data to api/uc.php under each application. The data is received by uc.php and then performs corresponding login operations.

This is what I wrote. It’s basically the same as his. I wanted to write down every function in detail but I’m a little tired today. Haha, it’s easy to find it yourself.

1. Start with user xxx entering the user name and password in login.php of a certain application. First use the uc_user_login function to verify the user and password on the uc server. If correct, write the session, write cookies, and update the login IP and login time in the application membership table. The user cannot feel this process.

2. Then notify the uc server through uc_user_synlogin that user xxx has successfully logged in. This process may use ajax, and the user will not feel the notification process.

3. After receiving this message, the uc server immediately ordered its subordinates to send the xxx login message, like a token ring, to all other applications that are willing to receive this message (whether the synchronous login is enabled in the background). In fact, it is to access the uc.php of each application with parameters, and the user cannot feel this process.

4. Each application relies on uc.php under the API to receive messages from the uc server, obey the instructions of the uc server, and do whatever it asks. Now, after receiving the command for user xxx to log in to your program, execute it immediately. And write the session of this application, and use p3p to write cookies in the same domain or different domains. The user cannot feel this process.

5. Finally, all programs integrated with uc, xxx logged in successfully. After the user logs in from www.phpernote.com/bbs, the login is also displayed when jumping to www.phpernote.com/. Because both the bbs and news systems are logged in in the background.

6. The session between the application and the uc server ends.

Articles you may be interested in

  • How to remove ads from dedeCMS background login page
  • php Output Control In-depth understanding of the difference between ob_flush and flush
  • It is dangerous for multiple URLs on a website to access the same content
  • The difference between synchronous requests and asynchronous requests in http requests
  • JS setInterval and setTimeout usage analysis
  • Solution to the "Invalid parameter encountered" error that pops up when CuteFTP connects to the ftp server
  • The usage and difference of using break, continue, goto, return, exit to jump out of multiple loops in PHP
  • mysql The usage differences between tinyint, smallint, int and bigint types

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764139.htmlTechArticleMost friends who are doing PHP development know that there is a ucenter that can be used to log in to multiple sites at the same time and log out at the same time, and user synchronization function. The author below will explain how ucenter implements synchronous login...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template