Home Backend Development PHP Tutorial 两个项目(分别在两台服务器下),如何给它们做同一个登陆功能呢?求思路

两个项目(分别在两台服务器下),如何给它们做同一个登陆功能呢?求思路

Jun 13, 2016 pm 01:18 PM
com cookie php session

两个项目(分别在两台服务器上),怎么给它们做同一个登陆功能呢?求思路
项目a:部署在192.168.0.1上
项目b:部署在192.168.0.2上

现在要做个项目c,要实现的功能是登陆功能:a、b项目都要通过c登陆以后才能访问。

登陆状态我准备保存到Cookie中,但是a和b在两台不同的服务器上,要怎么传递这个会话(Cookie)呢?
求思路,谢谢!

------解决方案--------------------
如果一天后仍未有满意答案,我就来解答
------解决方案--------------------
session写在表中或在内存缓存中 只在一个地方维护用户的状态
------解决方案--------------------
如果是一二级域名 设置cookie的作用域为根域名
不同的域名可将sessionid跟在url后面 再进行验证
session写入表的时候 取头信息加IP进行加密 在直接输域名的情况下取这一段信息进行验证
类似这样 sprintf('%08x', crc32(!empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] . ROOT_PATH . $ip . $session_id : ROOT_PATH . $ip . $session_id));

版主说不定有更好的解决方法
------解决方案--------------------
你可以去研究一下单点登录 
我们的设想是将 PHP 的 Session 数据集中存储,这样对于不同服务器中运行的 PHP 来说,只有一个共有的 Session 数据库,那么用户在服务器 A 登录所生成的 Session 数据在服务器 B、C、D 等服务器都可以共享,就可以免除多次登录。但由于 PHP 的 Session 是需要 Cookie 的,而 Cookie 又是与域名相关的,所以采用这个方案的各个服务器需要有相同的域名(至少是相同的二级域名),比如:
1、所有服务器的域名都是 www.whybsd.com,这个东东 DNS 轮询就可以实现;这个时候,在 PHP 中将 Cookie 域名设置为 www.whybsd.com 即可;
2、所有服务器的域名都是以 .whybsd.com 结尾的三级域名,比如 a.whybsd.com,b.whybsd.com 等等,这个时候,在 PHP 中将 Cookie 域名设置为 .whybsd.com 就可以共享 Cookie 了。
------解决方案--------------------
用CAS
------解决方案--------------------
http://www.phpweblog.net/linxiaobo/archive/2009/04/15/6419.html
这是常见的一种,地址我随便搜的,P3P 后面的一串记不下来,你可以看看。稍微看了一下,只要P3P设置正确,肯定可以。这种方案个人解决过跨域cookie问题。

需要注意两个域名对应的地方。。不加P3P,IE,Safari【不确定】通不过的,这大概叫第三方cookie?


另外还可以是借助iframe【这可没有跨域的概念】,不同的域父子框架之间传值,可通过url锚点……思路自己扩展咯

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 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)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles