gpt4 book ai didi

cookies - 在 ColdFusion (HTTPS) 中读取跨域(跨子域)Cookie

转载 作者:行者123 更新时间:2023-12-04 12:12:11 24 4
gpt4 key购买 nike

我需要读取在 https://sub1.domain.com 上创建的 cookie来自 http://origin.domain.com使用 ColdFusion。我已经看到很多关于如何使用 CFCOOKIE 在子域中创建 cookie 的信息,但我不知道如何访问已经存在的 cookie。

无论如何,HTTPS 会让这成为不可能吗?

附录:
下面的检查答案正确地解决了上述措辞的问题。就我而言,它不起作用。我应该解释一下:sub1.domain.com 上的 cookie 是由托管的第三方产品创建的 - 不是用 Coldfusion 编写的,也不在我的控制之下。

最佳答案

这真的很容易。当您创建 cookie 时,请为其指定一个与您的域相同的域属性。要记住的重要部分是它必须有一个前导点。

<cfcookie name="mycookie" value="myvalue" domain=".mydomain.com" path="/" />

前导点告诉浏览器将 cookie 发送到 mydomain.com 的任何子域,其中包括 sub.mydomain.com 和 blah.mydomain.com。

然后,您就可以像访问任何其他 cookie 一样从任何子域访问 cookie:
<cfset thevalue = cookie.mycookie />

您应该将此作为支持旧浏览器的最佳实践。

这是来自 RFC2109 的声明:可能影响旧浏览器的 HTTP 状态管理机制

"To prevent possible security or privacy violations, a user agent rejects a cookie (shall not store its information) if… The value for the Domain attribute contains no embedded dots or does not start with a dot."



我相信这被 RFC 2965: HTTP State Management Mechanism 所覆盖,该机制指出

"Domain=value OPTIONAL. The value of the Domain attribute specifies the domain for which the cookie is valid. If an explicitly specified value does not start with a dot, the user agent supplies a leading dot."



这解释了为什么它可能适用于您,大概是现代浏览器。我仍然建议你添加它。

关于cookies - 在 ColdFusion (HTTPS) 中读取跨域(跨子域)Cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8497981/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com