Table of Contents
Reply content:
Home Backend Development PHP Tutorial linux - Which solution is better for PHP single sign-on?

linux - Which solution is better for PHP single sign-on?

Jul 06, 2016 pm 01:52 PM
linux php session Log in

UCente is relatively ready-made, but it does not fit well with my project. How should I configure it when using a shared session server? Can anyone give me good advice and direction? Thank you!

Reply content:

UCente is relatively ready-made, but it does not fit well with my project. How should I configure it when using a shared session server? Can anyone give me good advice and direction? Thank you!

I have answered the same question before, so I will take it out again and answer it again.
Please read the title

First of all, I would like to remind you not to be frightened by new technologies, and do not check SSO (Single Sign On). This will only increase the complexity of your problem and your fear of this problem. In fact, It's really not that difficult.


Let me help you break down the problem. The Session multi-terminal login you mentioned can actually be broken down into Session shared login. It is not an advanced thing. It is nothing more than the required Session value when different servers have different domain names. It is accessible and allows everyone to read the same Session value. The important thing is the same session_id() value. In this case, each (server/project) reads the same data. Since they all read the same data (especially the same session_id() value), then we can use this identifier to make different Users display different content, and the problem of multiple logins is solved

(To simplify the problem, logging in is a special process for users. From the perspective of us developers, it is nothing more than letting different people read different data, and we only need to obtain That login identifier will do).

In other words, the key technical points of session sharing lie in two points:

1. Let the client access the same sessionId,
2. The location of the Session data accessed by servers corresponding to all domain names must be consistent

The following focuses on the implementation. Session sharing is more complicated than cookie sharing because there are relatively many situations. There are about four situations

The same server has the same domain name, the same server has different domain names, different servers have the same domain name, and different servers have different domain names.

Implementation of the same server and the same domain name (different subdomain names):

The implementation is relatively simple. Just find an online demo (picture intrusion and deletion) and follow the following code to implement it.
linux - Which solution is better for PHP single sign-on?

Implementation of different domain names on the same server:

In this case, we once again clarify the key technical points to achieve session sharing, the same sessionId, the same data source.
If you have different domain names, you must first cross-domain the cookie ('PHPSESSID'), and then use this sessionid value to obtain the corresponding data from the MySQL database or Nosql, thus realizing session sharing with different domain names on the same server.
The first is cookie cross-domain:
linux - Which solution is better for PHP single sign-on?

Then there is Redis data sharing. The key is session_id and the value is the data that needs to be shared. Redis cluster technology is used. The example is too complicated. If you are interested, you can directly go to the article to view: redis cluster cluster installation and configuration details

Implementation of the same domain name on different servers:

This situation is similar to , but in this case there is no need to consider the issue of cookie cross-domain, so just focus on data sharing, the same as above , the key is sessio_id, the value is the specific data value, refer to the article above for detailed explanation of redis cluster cluster installation and configuration.

Implementation of different server names and different domain names:

This situation and Graph visit also have to achieve two goals, the same sessionId,Same data source. If the domain name is different, you must first cross-domain the cookie ('PHPSESSID'), and then use this sessionid value to obtain the corresponding data from the MySQL database or Nosql, thus realizing session sharing with different domain names on the same server.
The first is cookie cross-domain:
linux - Which solution is better for PHP single sign-on?

Then there is Redis data sharing. The key is session_id and the value is the data that needs to be shared. Redis cluster technology is used. The example is too complicated. If you are interested, you can directly go to the article to view: redis cluster cluster installation and configuration detailed explanation.

We found that the solutions in the four cases are similar, the second case and the fourth case is basically the same. The core idea is to solve two root problems. Everyone needs to get the same session_id, and there is a shared data source that everyone needs to get.

After understanding these two points, SSO shared by Session will be a matter of course.
If you have any questions, you can ask directly in the comment area and I will answer immediately.

If you can’t use ucenter, don’t use it. . . It just hurts

In addition to SSO, there is also the issue of user data integration.
In order to solve this problem, I simply developed a website building program that supports multiple sites and types.

Use cookies to store each user’s information independently

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

Video Face Swap

Video Face Swap

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

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)

PHP: An Introduction to the Server-Side Scripting Language PHP: An Introduction to the Server-Side Scripting Language Apr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

PHP and the Web: Exploring its Long-Term Impact PHP and the Web: Exploring its Long-Term Impact Apr 16, 2025 am 12:17 AM

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

PHP vs. Python: Use Cases and Applications PHP vs. Python: Use Cases and Applications Apr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

How to switch Chinese mode with vscode How to switch Chinese mode with vscode Apr 15, 2025 pm 11:39 PM

VS Code To switch Chinese mode: Open the settings interface (Windows/Linux: Ctrl, macOS: Cmd,) Search for "Editor: Language" settings Select "Chinese" in the drop-down menu Save settings and restart VS Code

See all articles