1, the user login discuz, through the logging.php file function Uc_user_login to post the data validation, that is, username and password to verify.
2. If the validation succeeds, the function Uc_user_synlogin located in the client.php file under Uc_client will be invoked to invoke Uc_api_post (' user ', ' synlogin ', Array (' UID ') in this function. > $uid)).
3, then this function to Ucenter index.php pass the data, index.php accept the transmitted data, get model user,action for the Synlogin value.
4, Then Ucenter's index.php invokes the Onsynlogin method in the User.php class under the control directory, using the Foreach loop to notify the UC application list of the application to open the synchronous login in a synchronous logon; that is, passed to the uc.php some data with the API in the directory.
5, uc.php receives the notification and processing get over the data, and in the function Synlogin (in uc.php) through the function _authcode encrypts the data (by default Uc_key as the key), uses the function _setcookie to set the cookie.
6, each application with the corresponding key to decode the cookie set above, get the user ID and other data, through this value to determine whether the user has been logged through other applications, so that users can automatically login.
The api/uc.php in the logging.php-->uc_client of the application is client.php-->ucenter--> in other applications.
In fact, ucenter implementation of the principle of synchronous landing is a cookie, a successful application after landing, to Ucenter pass data, let Ucenter notify other applications also set cookies, so that users access to other applications through the set of cookies to achieve automatic landing.
The first step is to install Ucenter and then copy the Uc_client folder into your project, and then configure a few files
client.php equivalent function library
uc.php equivalent to callback file
Config.php is a configuration file
When you have 2 applications that are set up synchronously after landing when you log in an application then execute
Copy Code code 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 ' Login succeeded ';
} elseif ($uid = = 1) {
Echo ' user does not exist, or is deleted ';
} elseif ($uid = = 2) {
echo ' password error ';
} else {
echo ' undefined ';
}
Uc_user_synlogin () This function represents the simultaneous login to all other open sync login functions UC itself will be in the background to all open synchronous landing applications to loop through and then on the page output
Copy Code code as follows:
<script type= "Text/javascript" src= "http://www.lihuai.net/wp-content/uploads/sp/uc.php?time=1408327309& code=bc6bfla6wh343nin2gan%2f82y9cncennpk1gclgyhdqf4wsxsosdtyqbb2nuoxe0ujqzwmwncdx%2ffq1gk6fs% 2bqjqi2axvg2oq1pd9c1wzy%2bgjxs7qo4mm2sxfvhww7jnjkgpdkvddqtyeybksisz7yrdb0zfuxh2yr3cq "reload=" 1″></script >
<script type= "Text/javascript" src= "http://www.lihuai.net/wp-content/uploads/sp/uc.php?time=1408327309& code=206flcqeb%2faft% 2fdfpno9bvqsb1b0o6xtzdibyood7ec11vmrjzc7paklo0lf3tgihwlwzkwdw5vdhq866mgulsco5nekfkl341vwp7bpabnzpntgg7m4jzpfdx6nvp0ltjlyi %2bkebi7ulm58atk8ex4skbj%2ffdkjh%2f8z "reload=" 1″></script>
Like this kind of JS code, is sent to each open synchronous landing application, and then each open synchronous landing application of the callback file uc.php will be decrypted after the decryption, you can actually write your own code, this uc.php callback file code does not have to follow their format to write, You can also write your own code yourself.
In fact, the principle of UC is very simple, is an application after landing, and then the background polling sent to the application of synchronous login callback file, callback file received the user ID, generate cookies or session and then enter the login mode.