How to use single sign UCenter

First, let's understand the next step login Ucenter

1, the user logs discuz, verified by function uc_user_login logging.php file for post over the data, that is, for the username and password for authentication.

2, if the verification is successful, it calls the function uc_user_synlogin client.php uc_client located in the file, in this function call uc_api_post ( 'user', 'synlogin' , array ( 'uid' => $ uid)).

3, then the transfer function data to index.php Ucenter of index.php receiving data transferred to obtain a model for the user, action of synlogin value.

4, then onsynlogin method user.php class in index.php call control Ucenter directory in, through foreach loop to notify the javascript landing uc application synchronization open the application list synchronization Log; that is passed through to get way Some data uc.php under each application directory api.

5, uc.php reception notification process and get over the data, and the function synlogin (located in uc.php) (default to UC_KEY as a key) encrypted data by _authcode function, a function to set a cookie _setcookie.

6, each application using a decoding key corresponding to the cookie set above, to obtain data such as user id; to determine whether this value by the user logged in through other applications, so that the user can automatically log.

Application logging.php ------> client.php ------ uc_client of> Ucenter ------> application api / uc.php

In fact Ucenter The principle is synchronized landing cookie, after the successful landing of an application, pass data to Ucenter, let Ucenter notify other applications also set a cookie, so that the user has been set by a good cookie when accessing other applications of automatic landing. Ucenter understand the principle of synchronization, and then landed face can not synchronize or development for some time and UCenter interface will be much easier.

First we have to install roughly step ucenter then uc_client copy this folder to your project and then go inside it in several configuration files
client.php equivalent library
uc.php equivalent callback file
there is a config.inc.php It is the configuration file

when you have two applications are set up after landing sync when you landed an application and then perform

[PHP] View Plain Copy
the include './config.inc.php';
the include './uc_client/client.php';
$ of usernames is = "feiye";
$ Passwords = "789 123";
List ($ UID, $ username, $ password, $ In Email) = uc_user_login ($ of usernames is, $ Passwords);
IF ($ UID> 0) {
the setcookie ( "username ", $ username, Time () + intval (24-* 3600));
echo uc_user_synlogin ($ uid);
echo 'Login successful';
ELSEIF} ($ UID == -1) {
echo 'user does not exist, or deleted';
} ELSEIF ($ UID == -2) {
echo 'wrong password';
} the else {
echo 'undefined';
}

uc_user_synlogin () this function represents a function to be synchronized to a different landing landing uc sync all open in the background, they will apply to all open landing gave synchronization loop through it again and then output on the page

[HTML] Copy Plain View
<Script of the type = " text / JavaScript "the src =" http://127.0.0.70/api/uc.php?time=1374540644&code=14fdIufn%2B2YwkQlN9P07FEHOfZvDJupvgBgaRPn7R0DJmbEwCb23vKwO1uaeybLq3HZhtokoZrnqu7NGi09jzs684drFCbLDiSpKhk6P50MftBRA3vp4yIswhrPMl1dXo5ajB7CVZ9F8EI%2BkdFfq0E0rdyeRkuz8goeHhg "= reload". 1 "> </ Script>
[HTML] Plain View Copy
<Script type = "text / javascript" src = "http://127.0.0.71/api/uc.php?time=1374540644&code=07a91g8SepQwwfA3C1uN1sPhC4v6yuER1jFbVTQMK%2BQZmTkjwOz8X%2B8rWgNmKdhlXe9XXVQqAkDjN26CK6BMA19ZpLoiSW4wuNnxHAB9xXLt2VExuyf03MnEHAC%2BUdjwb58sbXGcYUpM4Bmzdm3Q92ObSp0Kk2qCd12fqg "= reload". 1 "> </ Script>

similar to this js code  each opening is synchronized to a login the application then callback file applications received each opening uc.php sync after landing will be decrypted decipher fact, you'll be able to write their own code this code uc.php callback file does not have to follow their format you can also write your own code to write your own example, I do synchronization session is based on the landing

[PHP] View Plain Copy
function synlogin ($ GET, $ POST) {
$ uid = $ GET [ 'uid'];
$ username = $ GET [ 'username'];
IF (API_SYNLOGIN!) {
return API_RETURN_FORBIDDEN;
}
header ( 'the P3P: the CP = "CURa ADMa DEVa PSAo PSDO the OUR BUS the UNI PUR the INT on DEM the STA the PRE the COM the NAV the OTC the NOI the DSP COR"') ;
the setcookie ( 'gwyy', $ username, Time () + 3600, '/', '127.0.0.71');
_setcookie (.. 'Example_auth', _authcode ($ UID "\ T" $ username, 'the ENCODE')) ;

$ _SESSION [ 'username'] = $ username;
$ _SESSION [ 'UID'] = $ UID;
}

function synlogout ($ GET, POST $) {
(! API_SYNLOGOUT) IF {
return API_RETURN_FORBIDDEN;
}
// Note synchronization Sign API interface
header ( 'the P3P: the CP = "CURa ADMa DEVa the UNI PUR PSAo the INT BUS PSDO the OUR the STA on DEM the PRE the COM the NAV the OTC the NOI the DSP COR"');
_setcookie ( 'Example_auth', '', 365 * -86.4 thousand);
the unset ( _SESSION $ [ 'username']);
the unset ($ _ the SESSION [ 'UID']);
the session_destroy ();
}

after this another application when the user set a page automatically landed

Guess you like

Origin www.cnblogs.com/meizhoulqp/p/11606318.html