


UCenter single sign-on/synchronous login/synchronous logout instance_PHP tutorial
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

PHPsessionscanstorestrings,numbers,arrays,andobjects.1.Strings:textdatalikeusernames.2.Numbers:integersorfloatsforcounters.3.Arrays:listslikeshoppingcarts.4.Objects:complexstructuresthatareserialized.

TostartaPHPsession,usesession_start()atthescript'sbeginning.1)Placeitbeforeanyoutputtosetthesessioncookie.2)Usesessionsforuserdatalikeloginstatusorshoppingcarts.3)RegeneratesessionIDstopreventfixationattacks.4)Considerusingadatabaseforsessionstoragei

Session regeneration refers to generating a new session ID and invalidating the old ID when the user performs sensitive operations in case of session fixed attacks. The implementation steps include: 1. Detect sensitive operations, 2. Generate new session ID, 3. Destroy old session ID, 4. Update user-side session information.

PHP sessions have a significant impact on application performance. Optimization methods include: 1. Use a database to store session data to improve response speed; 2. Reduce the use of session data and only store necessary information; 3. Use a non-blocking session processor to improve concurrency capabilities; 4. Adjust the session expiration time to balance user experience and server burden; 5. Use persistent sessions to reduce the number of data read and write times.

PHPsessionsareserver-side,whilecookiesareclient-side.1)Sessionsstoredataontheserver,aremoresecure,andhandlelargerdata.2)Cookiesstoredataontheclient,arelesssecure,andlimitedinsize.Usesessionsforsensitivedataandcookiesfornon-sensitive,client-sidedata.

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver CS6
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
