如何在两个不同的域中使用 cookie?
我需要使用 cookie 在两个不同的域之间共享 SSO 信息,这可以在 PHP 中实现吗?如何实现?
I need to share SSO information between two different domains with a cookie, can this be done in PHP and how?
推荐答案
在两个域上,放置从另一个域中提取的图像或其他 Web 元素.使用 URL 通知其他域用户 X 在域 A 上,并让域 B 将该用户 ID 与其系统上的该用户相关联.
On both domains, place an image or other web element that is pulled from the other domain. Use the URL to notify the other domain that user X is on domain A, and let domain B associate that user ID with that user on their system.
正确执行有点复杂,但如果你仔细考虑它会很有效.
It's a little complex to carry out correctly, but if you think it through it'll work out very well.
Vinko 在评论中指出(谢谢!)我不应该认为您了解所涉及的安全风险是理所当然的.如果此信息对任何人都有价值,那么您应该确保使用适当的加密、身份验证等,以避免发布敏感信息并避免各种攻击(重播、中间人等).这应该不会太麻烦,因为您可以控制两个网站,并且可以为这两个网站选择一个安全的密钥,因为通信仅通过这个特殊的 URL 在两个服务器之间进行.不过请记住.
Vinko points out in a comment (thanks!) that I shouldn't take it for granted that you understand the security risks involved. If this information is of any value to anyone, then you should make sure you use proper encryption, authentication, etc to avoid releasing sensitive information and to avoid various attacks (replay, man in the middle, etc). This shouldn't be too onerous since you control both websites and you can select a secure secret key for both, since the communication is only going between the two servers via this special URL. Keep it in mind though.
-亚当
相关文章