Home Backend Development PHP Tutorial UCenter single sign-on/synchronous login/synchronous logout instance_PHP tutorial

UCenter single sign-on/synchronous login/synchronous logout instance_PHP tutorial

Jul 13, 2016 am 10:48 AM
member Synchronize Example have friend Sign out Log in

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_CONNECT’, ’mysql’); // 连接 UCenter 的方式: mysql/NULL, 默认为空时为fscoketopen()

//数据库相关 (mysql 连接时, 并且没有设置 UC_DBLINK 时, 需要配置以下变量)
define(‘UC_DBHOST’, ’localhost’); // UCenter 数据库主机
define(‘UC_DBUSER’, ’root’); // UCenter 数据库用户名
define(‘UC_DBPW’, ’123′); // UCenter 数据库密码
define(‘UC_DBNAME’, ’ucenter’); // UCenter 数据库名称
define(‘UC_DBCHARSET’, ’utf8′); // UCenter 数据库字符集
define(‘UC_DBTABLEPRE’, ’ucenter.uc_’); // UCenter 数据库表前缀
define(‘UC_KEY’, ’safefewfef’); // 与 UCenter 的通信密钥, 要与 UCenter 保持一致
define(‘UC_API’, ’http://www.bKjia.c0m/uc’);// UCenter 的 URL 地址, 在调用头像时依赖此常量
define(‘UC_CHARSET’, ’utf-8′); // UCenter 的字符集
define(‘UC_IP’, ’127.0.0.1′); // UCenter 的 IP, 当 UC_CONNECT 为非 mysql 方式时, 并且当前应用服务器解析域名有问题时, 请设置此值
define(‘UC_APPID’, ’3′); // 对应到ucenter当前应用的 ID
define(‘UCDOMAIN’,'http://www.bKjia.c0m/’); // 域名设置

//一些 Cookie 设置
$_UC = array();
$_UC["cookiedomain"] = ”; // cookie 作用域
$_UC["cookiepath"] = ’/'; // cookie 作用路径
$_UC["cookiepre"] = ’uc_’; // cookie 前缀
$_UC["cookietime"] = ’31536000′; //cookie 作用时间

define(‘UC_CONNECT’, ’mysql’); // How to connect to UCenter: mysql/NULL, the default is fscoketopen() //Database related (when mysql is connected and UC_DBLINK is not 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’); // 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]:

Only using PHP, Kangsheng’s solution is quite good, and it uses the p3p header to achieve single sign-on for different domain names
The code is as follows
 代码如下 复制代码

include_once ’../config.php’;
include_once ’../uc_client/client.php’;

Copy code

 代码如下 复制代码
list($uid, $username, $password) = uc_user_login($_POST[username], $_POST[password]);//进入ucenter验证
$ucsynlogin = uc_user_synlogin($uid);//同步登录
echo $ucsynlogin;//因为是ajax 要echo
include_once ’../config.php’;
include_once ’../uc_client/client.php’;

Your verification login section

The disadvantage is that using ajax client request, if there are more than 10 applications, the login speed will slow down. At this time, you can consider Qiye’s Loong SSO

After understanding the above things, it is not difficult to communicate between PHP’s CMS and ucenter. http://www.bkjia.com/PHPjc/632783.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/632783.html
TechArticle
ucenter I think many friends will use it. It is a member synchronization function. We often combine several System or different forums are integrated, let me introduce it to you. ...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to buy WeChat reading membership cheaply? Share the best way to buy membership on WeChat Reading! How to buy WeChat reading membership cheaply? Share the best way to buy membership on WeChat Reading! Mar 16, 2024 am 08:22 AM

1. How to buy WeChat reading membership cheaply? Share the best way to buy membership on WeChat Reading! 1. Open the WeChat Reading APP. There is a reading challenge in the reading welfare special session. Participate in the reading challenge. 2. Pay 1 yuan to participate, read for 7 days, duration >7 hours, and get a 4-day paid membership card with 4 book coins. You can participate for about 52 weeks in a year. If you participate every time, it will cost a total of 52 yuan, and you can get a total of 208 days. Paid membership card 208 book coins. 3. Pay 3 yuan to participate, read for 14 days, duration >14 hours, and get a 10-day paid membership card with 10 book coins. You can participate about 26 times a year. If you participate every time, it will cost a total of 78 yuan, and you can get a total of 260 days. Paid membership card costs 260 book coins. 4. Pay 4 yuan to participate and read for 21 days

What should I do if I download other people's wallpapers after logging into another account on wallpaperengine? What should I do if I download other people's wallpapers after logging into another account on wallpaperengine? Mar 19, 2024 pm 02:00 PM

When you log in to someone else's steam account on your computer, and that other person's account happens to have wallpaper software, steam will automatically download the wallpapers subscribed to the other person's account after switching back to your own account. Users can solve this problem by turning off steam cloud synchronization. What to do if wallpaperengine downloads other people's wallpapers after logging into another account 1. Log in to your own steam account, find cloud synchronization in settings, and turn off steam cloud synchronization. 2. Log in to someone else's Steam account you logged in before, open the Wallpaper Creative Workshop, find the subscription content, and then cancel all subscriptions. (In case you cannot find the wallpaper in the future, you can collect it first and then cancel the subscription) 3. Switch back to your own steam

How do I log in to my previous account on Xiaohongshu? What should I do if the original number is lost after it is reconnected? How do I log in to my previous account on Xiaohongshu? What should I do if the original number is lost after it is reconnected? Mar 21, 2024 pm 09:41 PM

With the rapid development of social media, Xiaohongshu has become a popular platform for many young people to share their lives and explore new products. During use, sometimes users may encounter difficulties logging into previous accounts. This article will discuss in detail how to solve the problem of logging into the old account on Xiaohongshu, and how to deal with the possibility of losing the original account after changing the binding. 1. How to log in to Xiaohongshu’s previous account? 1. Retrieve password and log in. If you do not log in to Xiaohongshu for a long time, your account may be recycled by the system. In order to restore access rights, you can try to log in to your account again by retrieving your password. The operation steps are as follows: (1) Open the Xiaohongshu App or official website and click the "Login" button. (2) Select "Retrieve Password". (3) Enter the mobile phone number you used when registering your account

How to get qq music membership for free? Tutorial on getting QQ Music membership for free How to get qq music membership for free? Tutorial on getting QQ Music membership for free Mar 13, 2024 pm 08:37 PM

QQ Music is a music-listening software used by many users. Some songs here require users to have membership before they can download and play them. So how to get QQ Music membership for free? Let this site give users a detailed introduction to the tutorial on how to obtain QQ Music membership for free. Tutorial on getting QQ Music membership for free 1. First, we open QQ Music. 2. Go to my homepage and click on the three horizontal lines in the upper right corner. 3. Click to open the free music listening mode here. 4. A 15-second advertisement will appear here. We only need to wait for the advertisement to end to get a thirty-minute membership experience. Experience time can be superimposed. 5. Obtain a membership after reading it. Receive 1 day of QQ music

One or more items in the folder you synced do not match Outlook error One or more items in the folder you synced do not match Outlook error Mar 18, 2024 am 09:46 AM

When you find that one or more items in your sync folder do not match the error message in Outlook, it may be because you updated or canceled meeting items. In this case, you will see an error message saying that your local version of the data conflicts with the remote copy. This situation usually happens in Outlook desktop application. One or more items in the folder you synced do not match. To resolve the conflict, open the projects and try the operation again. Fix One or more items in synced folders do not match Outlook error In Outlook desktop version, you may encounter issues when local calendar items conflict with the server copy. Fortunately, though, there are some simple ways to help

Instructions for automatic renewal and cancellation of Kugou Music APP membership Instructions for automatic renewal and cancellation of Kugou Music APP membership Mar 19, 2024 pm 07:28 PM

How to cancel automatic membership renewal on Kugou Music APP? There are many users who have applied for Kugou Music’s VIP auto-renewal service. Later, they want to cancel this service, but they don’t know where to cancel it. Below, I will bring you a tutorial on how to cancel the auto-renewal of Kugou Music. I hope it will be helpful to everyone. . It is very simple to cancel automatic renewal in Kugou Music APP: just enter the member center, find the music package/luxury VIP option, select automatic renewal enabled, and then click to close renewal. 2. WeChat: As shown in the picture below, go to the payment page, click the three dots in the upper right corner, select the deduction service, click Kugou Music to close the service; 3. Alipay: Go to the settings page, select payment settings, and select password-free payment/ Automatically deduct fees, and finally choose Kugou Music to terminate the contract.

How to cancel automatic renewal for Zhihu app members How to cancel automatic renewal for Zhihu app members How to cancel automatic renewal for Zhihu app members How to cancel automatic renewal for Zhihu app members Mar 13, 2024 am 11:04 AM

How to cancel the automatic renewal of Zhihu app membership? Zhihu app is a very practical mobile software. This software has many functions, and each function will bring a different feeling to the users. There are some contents on this software that require users to register as a member before they can read them. Membership on this software is not expensive, and continuous monthly membership will be cheaper. Some players want to know how to cancel automatic renewal. The editor below has compiled methods for canceling automatic renewal for your reference. How to cancel automatic renewal for Zhihu app members Zhihu members can choose four renewal methods, including Apple Pay, WeChat Pay, Alipay Pay and Baidu Pay. For users who choose Baidu Pay, renewal can be managed through WeChat or Alipay payment.

How to get Bilibili membership for free? Free for big members of B station How to get Bilibili membership for free? Free for big members of B station Mar 15, 2024 pm 05:00 PM

Bilibili is a video playback platform with rich resources, including a dance area, ghost animal area, food area, animal area, etc. But now many times you need to be a member to watch videos on site B. If you don’t want to spend money, can you get a member of site B? The editor here will bring you how to get the free membership of Bilibili. I hope it can help you. How to get free membership on Bilibili: Open Bilibili and click "My". Click the "Creation Home" icon in the "Creation Center" area. After entering the creation center, click "Task Center". After entering the task center, read the corresponding tasks and complete them to get points.

See all articles