UCenter single-point logon/synchronous logout instance _ PHP Tutorial

Source: Internet
Author: User
Tags keyword list
UCenter single-point login synchronous logout instance. I think many of my friends will use the ucenter feature, which is a member synchronization function. we often integrate several systems or different forums. next I will introduce it to you. I think many of my friends will use the ucenter feature, which is a member synchronization function. we often integrate several systems or different forums. next I will introduce it to you.

UCenter synchronization process:

The premise is that you need to add the applications that require synchronous login to the Ucenter (at least two applications can see the effect), and display: the communication is successful.

Assume that I have added two application websites, A and B.

1. first, when you log on to station A, after successful logon, the actual solution is to call the methods provided by uc_client to obtain two script codes (Station A and Station B) from UCenter ), the two script codes are the APIs/uc for accessing sites A and B. the logon method in php allows you to perform the session and cookie operations required for logon in the method.

2. when logging out, the operation and logon are the same. you need to obtain two script codes from the UCenter to trigger APIs/uc on site A and Site B. php logout method.

Note: after obtaining two script codes, you must run the code in the output browser. otherwise, synchronous login and logout will not be implemented.

Suggestion: you can use browser monitoring to view the returned output values during development and debugging. I used chrome F12 to open the Network tag.

Instance details

The so-called single sign-on means that several sites share a single user Center for synchronous login and exit.

Server: Loog SSO

Customer service: ucenter. To be honest, the commercialization of dz has indeed led php to develop a lot.

Basic principles of ucenter:

In fact, users log on to the console, but ajax users won't find it.

Let's take a look at the specific procedures with ucenter:

Config. php [PHP code]:

The code is as follows:

Define ('UC _ CONNECT ', 'mysql'); // method for connecting to UCenter: mysql/NULL. the default value is fscoketopen ()

// Database-related (the following variables must be configured when UC_DBLINK is not set during mysql connection)
Define ('UC _ dbhost', 'localhost'); // UCenter database host
Define ('UC _ dbuser', 'root'); // user name of the UCenter database
Define ('UC _ DBPW ', '000000'); // 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'); // The communication KEY of the UCenter, which must be consistent with that of the UCenter.
Define ('UC _ API ', 'http: // www. bKjia. c0m/UC'); // The URL of the UCenter, which depends on this constant when calling the Avatar
Define ('UC _ charset', 'utf-8'); // UCenter character set
Define ('UC _ IP', '2017. 0.0.1 '); // UCenter IP address. set this value when UC_CONNECT is not in mysql mode and the domain name is resolved by the current application server.
Define ('UC _ APPID ', '3'); // ID corresponding to the current ucenter application
Define ('ucdomain ', 'http: // www. bKjia. c0m/'); // Set the domain name

// Some Cookie settings
$ _ UC = array ();
$ _ UC ["cookiedomain"] = "; // cookie scope
$ _ UC ["cookiepath"] = '/'; // cookie action path
$ _ UC ["cookiepre"] = 'UC _ '; // cookie prefix
$ _ UC ["cookietime"] = '000000'; // cookie validity period

After the configuration file is written, add an application to the ucenter background to remember that the custom 'UC _ key' must be the same as that in config. php.

The next step is the api/uc. php in your home directory.

For example, if the application url is filled in as http://www.bKjia. c0m then I have the corresponding http://www.bKjia. c0m/api/uc. php

If you want to customize it, confirm your correspondence.

The most important thing is api/uc. php. synchronous login is to access the uc. php of each application. the dz has been given a demo.

[PHP code]:

The code is as follows:
Define ('api _ deleteuser', 0); // note the API deletion switch
Define ('api _ renameuser', 0); // note the API interface switch
Define ('api _ gettag', 0); // note
Define ('api _ synlogin', 1); // note: synchronous logon API switch
Define ('api _ synlogout', 1); // switch the synchronous logout API
Define ('api _ updatepw', 0); // note: change the user password
Define ('api _ updatebadword', 0); // The note function is used to update the keyword list.
Define ('api _ updatehosts', 0); // The note function is used to update the domain name resolution cache.
Define ('api _ UPDATEAPPS ', 0); // The note function is used to update the application list.
Define ('api _ UPDATECLIENT ', 0); // switch to update the client cache
Define ('api _ UPDATECREDIT ', 0); // The note function is used to update user points.
Define ('api _ GETCREDITSETTINGS ', 0); // note provides the point setting switch for UCenter.
Define ('api _ getcredentials', 0); // note
Define ('api _ updatecreditsettings', 0); // The note function is used to update the application points.

These parameters are all functional switches provided to other applications.

Finally, how can I log on to other applications synchronously on my own page?

[PHP code]:

The code is as follows:

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

Your login authentication section

The code is as follows:
List ($ uid, $ username, $ password) = uc_user_login ($ _ POST [username], $ _ POST [password]); // enter ucenter for verification
$ Ucsynlogin = uc_user_synlogin ($ uid); // synchronous login
Echo $ ucsynlogin; // because ajax requires echo

With only php, Kang Sheng's solution is quite good, and the p3p header is used to achieve single-point login for different domain names

The disadvantage is to use ajax client requests. if there are more than 10 applications, the login speed will slow down. at this time, you can consider Loong SSO for the next seven nights.

After learning about the CMS and ucenter communication of Dongdong php, it is not difficult.

....

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.