ucenter I think many friends will use it. It is a member synchronization function. We often integrate several systems or different forums. Let me introduce it to you.
UCenter synchronization process:
The premise is that you need to add applications that require simultaneous login on Ucenter (at least 2 to see the effect), and display: Communication successful
Suppose I add two application websites A and B
1. First, when site A logs in, after the login is successful, the essence of the process is to call the method provided by uc_client to obtain two script codes (sites A and B) from UCenter. These two script codes are to access A and B. The login method in the website's api/uc.php can be used to perform the session and cookie operations required for login.
2. When logging out, the operation is the same as logging in. You need to obtain 2 script codes from UCenter. The purpose is to trigger the logout method in api/uc.php of stations A and B.
Important: After obtaining the two script codes, you must let the browser run in the output, otherwise synchronous login and logout will not be realized.
Suggestion: When developing and debugging, use browser monitoring to check the return output value. I was using chrome F12 and then opened the Network tab.
Detailed examples
The so-called single sign-on is nothing more than several sites sharing a user center to achieve synchronous login and synchronous logout.
Server side: Loog SSO
Customer service: ucenter, to be honest, the commercialization of dz has indeed made PHP develop a lot.
ucenter basic principle:
In fact, it is the user who logs in in the end, but the user will not notice it if ajax is used.
Let’s take a look at the specific procedures with ucenter:
config.php [PHP code]:
The code is as follows | Copy code | ||||
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’); // The communication key with UCenter must be consistent with UCenter define(‘UC_API’, ’http://www.bKjia.c0m/uc’);// URL address of UCenter, relying on this constant when calling the avatar define(‘UC_CHARSET’, ’utf-8′); // UCenter’s character set define(‘UC_IP’, ’127.0.0.1′); // The IP of UCenter. When UC_CONNECT is in non-mysql mode and the current application server has problems resolving the domain name, please set this value define(‘UC_APPID’, ’3′); // Corresponds to the ID of ucenter’s current application 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 application in the ucenter backend. Remember to customize the ‘UC_KEY’ which must be the same as in config.php
The next step is api/uc.php in your home directory
For example, if the application url is filled in as http://www.bKjia.c0m, then I will have the corresponding http://www.bKjia.c0m/api/uc.php
If you want to customize, please confirm your corresponding relationship.
The most important thing is api/uc.php. Synchronous login is to access uc.php of each application. Dz has already given a demo for this
[PHP code]:
代码如下 | 复制代码 |
define(‘API_DELETEUSER’,0); //note 用户删除 API 接口开关 define(‘API_RENAMEUSER’, 0); //note 用户改名 API 接口开关 define(‘API_GETTAG’, 0); //note 获取标签 API 接口开关 define(‘API_SYNLOGIN’, 1); //note 同步登录 API 接口开关 define(‘API_SYNLOGOUT’, 1); //note 同步登出 API 接口开关 define(‘API_UPDATEPW’, 0); //note 更改用户密码 开关 define(‘API_UPDATEBADWORDS’, 0); //note 更新关键字列表 开关 define(‘API_UPDATEHOSTS’, 0); //note 更新域名解析缓存 开关 define(‘API_UPDATEAPPS’, 0); //note 更新应用列表 开关 define(‘API_UPDATECLIENT’, 0); //note 更新客户端缓存 开关 define(‘API_UPDATECREDIT’, 0); //note 更新用户积分 开关 define(‘API_GETCREDITSETTINGS’, 0); //note 向 UCenter 提供积分设置 开关 define(‘API_GETCREDIT’,0); //note 获取用户的某项积分 开关 define(‘API_UPDATECREDITSETTINGS’, 0); //note 更新应用积分设置 开关 |
These parameters are function switches provided to other applications
Finally, how to log in to other applications simultaneously with your own page
[PHP code]:
The code is as follows
|
Copy code
|
||||
include_once ’../uc_client/client.php’;
Your verification login section |
http: //www.bkjia.com/PHPjc/632783.html