In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to achieve single sign-on Ucenter". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
First of all, let's take a look at the Ucenter login steps.
1. The user logs in to discuz and verifies the data from post through the function uc_user_login in the logging.php file, that is, to verify username and password.
2. If the verification is successful, the function uc_user_synlogin located in the client.php file under uc_client will be called and uc_api_post ('user',' synlogin', array ('uid'= > $uid) will be called in this function).
3. Then this function passes the data to the index.php of Ucenter, and the index.php accepts the passed data and gets the value with model as user,action and synlogin.
4. Then the index.php of Ucenter calls the onsynlogin method in the user.php class under the control directory, and through the foreach loop, notifies the applications in the uc application list that enable synchronous login to log in synchronously through the foreach loop, that is, it passes some data to the uc.php under api in each application directory through get.
5. Uc.php receives the notification and processes the data from get. In the function synlogin (located in uc.php), the data is encrypted by function _ authcode (default is UC_KEY as key), and the cookie is set with function _ setcookie.
6. Each application uses the corresponding key to decode the cookie set above to get the user id and other data; this value is used to determine whether the user has logged in through other applications, so that the user can log in automatically.
Logging.php of the application-> client.php- > Ucenter- > api/uc.php in the uc_client
In fact, the principle of synchronous login in Ucenter is cookie. After an application has successfully logged in, it transmits data to Ucenter and asks Ucenter to inform other applications that cookie is also set, so that users can log in automatically through the cookie that has been set up when they visit other applications. After understanding the synchronization principle of Ucenter, it will be much easier when you can't log in synchronously or develop some interface with UCenter.
In the rough step, we need to install ucenter first, then copy the uc_client folder into our project, and then configure several files.
Client.php is equivalent to a function library.
Uc.php is equivalent to a callback file.
And a config.inc.php is the configuration file.
When you have two apps set up to log in synchronously, when you log in to an app and execute
The copy code is as follows:
Include'. / config.inc.php'
Include'. / uc_client/client.php'
$usernames= "feiye"
$passwords= "789123"
List ($uid, $username, $password, $email) = uc_user_login ($usernames, $passwords)
If ($uid > 0) {
Setcookie ("username", $username,time () + intval (2403600))
Echo uc_user_synlogin ($uid)
Echo 'login successful'
} elseif ($uid =-1) {
Echo 'user does not exist or has been deleted'
} elseif ($uid =-2) {
Echo 'wrong password'
} else {
Echo 'undefined'
}
The function uc_user_synlogin () means to log in synchronously to all the other functions that enable synchronous login. Uc itself will loop through all the applications that enable synchronous login in the background and output them on the page.
The copy code is as follows:
The copy code is as follows:
The js code like this is sent to every application that enables synchronous login, and then the callback file of each application that opens synchronous login is received by uc.php and decrypted, and after it is decrypted, you can actually write the code yourself. The code of this uc.php callback file does not have to be written in their format, or you can write your own generation. For example, I do synchronous login based on session.
The copy code is as follows:
Function synlogin ($get, $post) {
$uid = $get ['uid']
$username = $get ['username']
If (! API_SYNLOGIN) {
Return API_RETURN_FORBIDDEN
}
Header ('P3P: CP= "CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"')
Setcookie ('gwyy',$username,time () + 3600 pas) 127.0.0.71')
_ setcookie ('Example_auth', _ authcode ($uid. "\ t". $username,' ENCODE'))
$_ SESSION ['username'] = $username
$_ SESSION ['uid'] = $uid
}
Function synlogout ($get, $post) {
If (! API_SYNLOGOUT) {
Return API_RETURN_FORBIDDEN
}
/ / note logs out the API API synchronously
Header ('P3P: CP= "CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"')
_ setcookie ('Example_auth',',-86400 * 365)
Unset ($_ SESSION ['username'])
Unset ($_ SESSION ['uid'])
Session_destroy ()
}
In this way, when the user refreshes another application page, he or she will log in automatically.
Note that if you add application prompts in UC that the communication is not successful, then the simple reason is that you did not find the http://xxxx/api/uc.php file, as long as there is this file, the communication will be successful.
In fact, the principle of UC is very simple: after a certain application logs in, and then the background polls the callback file sent to the synchronously logged-in application, the callback file receives the user ID, generates cookie or session, and then enters login mode.
"how to achieve single sign-on Ucenter" content is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.