两个项目(分别在两台服务器下),如何给它们做同一个登陆功能呢?求思路
两个项目(分别在两台服务器上),怎么给它们做同一个登陆功能呢?求思路
项目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锚点……思路自己扩展咯

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.
