search
HomeBackend DevelopmentPHP Tutorial Qeephp调整ucenter实现单点登陆之个人PHP项目与Ucenter整合

Qeephp整合ucenter实现单点登陆之个人PHP项目与Ucenter整合

前言

要实现使用ucenter单点登陆,则首先需要部署一个ucenter项目

一、下载ucenter程序

去Discuz官网下载一个ucenter程序

http://www.comsenz.com/downloads/install/ucenter

我下载的是下面这个版本的。

UCenter_1.6.0_SC_UTF8.zip


二、安装程序

php的安装环境我就不说了,将下载下来的ucenter程序部署完成。

我顺便部署了一下我的qeephp程序,这个和个人项目都是一样的,先保证运行正常。

我的配置:

ucenter域名:http://ucenter.webplus3.com

我的项目域名:http://www.nj-jz.com


三、开始整合

1、UCenter_1.6.0_SC_UTF8.zip解压

2、将advanced\examples\api文件夹下的uc.php文件拷贝到你网站的根目录下的api文件夹中,若没有api则新建一个api文件夹(api文件夹一定要在网站的根目录中)

3、将advanced\examples文件夹下的include文件夹拷贝到你项目的根目录。文件夹内包含一个文件叫db_mysql.class.php,这是连接数据库的类。

4、将uc_client文件夹整个复制到你网站根目录,uc_client之前说了是接口代码,现在根目录已经有include和uc_client两个文件夹了。

5、复制advanced\examples文件夹内的config.inc.php到你网站的根目录,这是配置UCenter的配置文件。

6、在ucenter后台中添加新应用,截图如下:


其他属性默认,点击“提交”,保存应用!

此时返回应用列表,通信状态应该是失败的!

别急,我们再修改一下配置文件。


四、修改ucenter配置

1.编辑应用,在应用提交按钮的下方会有一段配置


将这段配置信息拷贝到第(三)2步提到的uc.php文件的最上方。

添加后的文件前20行(其中2-15行是拷贝过来的配置)如下:

<?php define('UC_CONNECT', 'mysql');
define('UC_DBHOST', 'localhost');
define('UC_DBUSER', 'root');
define('UC_DBPW', '12344');
define('UC_DBNAME', 'web3_ucenter');
define('UC_DBCHARSET', 'utf8');
define('UC_DBTABLEPRE', '`web3_ucenter`.uc_');
define('UC_DBCONNECT', '0');
define('UC_KEY', '123456');
define('UC_API', 'http://ucenter.webplus3.com');
define('UC_CHARSET', 'utf-8');
define('UC_IP', '');
define('UC_APPID', '2');
define('UC_PPP', '20');

define('IN_DISCUZ', TRUE);

define('UC_CLIENT_VERSION', '1.5.0');	//note UCenter 版本标识
define('UC_CLIENT_RELEASE', '20081031');

同时按照这段配置信息更改第5步中说的config.inc.php文件里面相应的参数,使其与ucenter生成的配置信息保持一致。

<pre name="code" class="php"><?php define('UC_CONNECT', 'mysql');// 连接 UCenter 的方式: mysql/NULL, 默认为空时为 fscoketopen()
// mysql 是直接连接的数据库, 为了效率, 建议采用 mysql

//数据库相关 (mysql 连接时, 并且没有设置 UC_DBLINK 时, 需要配置以下变量)
define('UC_DBHOST', 'localhost');// UCenter 数据库主机
define('UC_DBUSER', 'root');// UCenter 数据库用户名
define('UC_DBPW', '12344');// UCenter 数据库密码
define('UC_DBNAME', 'web3_ucenter');// UCenter 数据库名称
define('UC_DBCHARSET', 'utf8');	// UCenter 数据库字符集
define('UC_DBTABLEPRE', 'web3_ucenter.uc_');	// UCenter 数据库表前缀

//通信相关
define('UC_KEY', '123456');// 与 UCenter 的通信密钥, 要与 UCenter 保持一致
define('UC_API', 'http://ucenter.webplus3.com');// UCenter 的 URL 地址, 在调用头像时依赖此常量
define('UC_CHARSET', 'utf-8');	// UCenter 的字符集
define('UC_IP', '');	// UCenter 的 IP
//当 UC_CONNECT 为非 mysql 方式时, 并且当前应用服务器解析域名有问题时, 请设置此&#20540;
define('UC_APPID', 2);	// 当前应用的 ID
define('UC_PPP', '20');

//同步登录 Cookie 设置
$cookiedomain = ''; 			// cookie 作用域
$cookiepath = '/';			// cookie 作用路径
以上步骤弄完后,回头再去看看你的ucenter后台,更新下缓存,再瞅瞅应用管理里面,看是不是已经通信成功了呢??


Statement
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
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.