如何在两个不同的域中使用 cookie?

How do I use cookies across two different domains?(如何在两个不同的域中使用 cookie?)
本文介绍了如何在两个不同的域中使用 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.

-亚当

这篇关于如何在两个不同的域中使用 cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)