Ucenter Single Sign-on/synchronous login/Sync Logout instance _php tutorial

Source: Internet
Author: User
Tags keyword list
Ucenter I think a lot of friends will use, is a member of the synchronization function, we will often put a few systems or different forums to integrate, I would like to introduce you to the students.

Ucenter Synchronization Process:

The premise is that you need to add an app that requires a synchronous login (at least 2 to see the effect) on the Ucenter, and shows that the communication was successful

If I add a, B, two app sites

1. First when the A station login, after the successful login, processing is essentially called Uc_client provides the method to ucenter get 2 script code (a, B station), these two script code is to access a, B two station api/ Uc.php the login method in the method, you can do the login required session and cookie operation.

2. When logged out, the operation and login are the same, you need to get 2 script code to Ucenter, the purpose is to trigger a, B station api/uc.php in the logout method.

Important: When you get to 2 script code, it is necessary to let the browser run the output, otherwise it will not implement synchronous login logout.

Recommendation: When developing debugging, using browser monitoring to see the return output values, I was using chrome F12 to open the Network tab.

Detailed examples

The so-called single sign-on, is nothing more than a few sites share a user center, to achieve synchronous landing, synchronous exit.

Server-side: Loog SSO

Customer Service: Ucenter, to tell the truth dz Commercialization really let PHP develop a lot.

Ucenter Fundamentals:

In fact, the end user is going to login just to use AJAX users will not find.

Let's take a look at the specific procedures and Ucenter:

config.php [PHP code]:

The code is as follows Copy Code

Define (' Uc_connect ', ' MySQL '); How to connect ucenter: Mysql/null, default is empty when Fscoketopen ()

//Database related (when MySQL is connected and no uc_dblink is set, the following variables need to be configured)
define (' uc_dbhost ', ' localhost ');//Ucenter Database host
define (' UC _dbuser ', ' root '); Ucenter database user name
define (' UC_DBPW ', ' 123′ ');//ucenter Database Password
define (' Uc_dbname ', ' ucenter ');//Ucenter database name
Define (' Uc_dbcharset ', ' utf8′ '); Ucenter database Character Set
define (' Uc_dbtablepre ', ' ucenter.uc_ ');//Ucenter database table prefix
define (' Uc_key ', ' safefewfef ');//With U Center's communication key, to be consistent with Ucenter
define (' Uc_api ', ' Http://www.bKjia.c0m/uc ');//Ucenter URL address, dependent on this constant when calling avatar
define ( ' Uc_charset ', ' utf-8′ '; Ucenter the character set
define (' uc_ip ', '′ ');//Ucenter IP, set this value when Uc_connect is not in MySQL mode, and the current application server resolves the domain name in the case of a problem
define (' uc_appid ', ' 3′ '); The ID corresponding to the current app of Ucenter
define (' Ucdomain ', ' http://www.bKjia.c0m/');//Domain name settings

Some Cookie settings
$_UC = Array ();
$_uc["Cookiedomain"] = "; Cookie Scope
$_uc["cookiepath"] = '/'; Cookie Action Path
$_uc["Cookiepre"] = ' uc_ '; Cookie Prefix
$_uc["cookietime"] = ' 31536000′; Cookie Action Time

After the configuration file is written, add an app to the Ucenter backstage and remember that the custom ' uc_key ' must be the same as the config.php inside.

Next is the api/uc.php in your home directory.

For example, the application URL is filled in as http://www.bKjia.c0m so I have a corresponding http://www.bKjia.c0m/api/uc.php.

If you want to customize, please confirm your correspondence.

The most important thing is api/uc.php, synchronous login is to access the application of uc.php about this DZ has given the demo

[PHP code]:

The code is as follows Copy Code
Define (' Api_deleteuser ', 0); Note User Delete API interface switch
Define (' Api_renameuser ', 0); Note User renamed API interface switch
Define (' Api_gettag ', 0); Note Get tag API interface switch
Define (' Api_synlogin ', 1); Note Sync Login API interface switch
Define (' Api_synlogout ', 1); Note Sync log out API interface switch
Define (' API_UPDATEPW ', 0); Note Change user password switch
Define (' Api_updatebadwords ', 0); Note Updating the keyword list switch
Define (' Api_updatehosts ', 0); Note Update the domain name resolution cache switch
Define (' Api_updateapps ', 0); Note Update App list switch
Define (' Api_updateclient ', 0); Note Update Client cache switch
Define (' Api_updatecredit ', 0); Note Update User points switch
Define (' Api_getcreditsettings ', 0); Note to Ucenter to provide the integration setting switch
Define (' Api_getcredit ', 0); Note Get a user's integral switch
Define (' Api_updatecreditsettings ', 0); Note Update Apply integration settings switch

These parameters are all functional switches provided to other applications.

Finally how to sync your own page with other apps

[PHP code]:

The code is as follows Copy Code

Include_once '. /config.php ';
Include_once '. /uc_client/client.php ';

Your authentication sign-in section

The code is as follows Copy Code
List ($uid, $username, $password) = Uc_user_login ($_post[username], $_post[password]);//Enter Ucenter authentication
$ucsynlogin = Uc_user_synlogin ($UID);//Synchronous login
echo $ucsynlogin;//Because Ajax is the Echo

PHP only, Hong Sing solution is relatively good, and the use of P3P head to achieve a different domain single sign-on

The disadvantage is the use of AJAX customer service request, if there are more than 10 applications, login speed is slow down, this time you can consider the next seven nights of Loong SSO

Understand the above stuff PHP cms and Ucenter communication is not difficult.

http://www.bkjia.com/PHPjc/632783.html www.bkjia.com true http://www.bkjia.com/PHPjc/632783.html techarticle Ucenter I think a lot of friends will use, is a member of the synchronization function, we will often put a few systems or different forums to integrate, I would like to introduce you to the students. ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.