简体   繁体   English

PHP中不同域的Cookie

[英]Cookie of different domains in PHP

是否可以使用php访问另一个域(例如example.com)中的域foo.com的Cookie?

No, it is not possible, cookie is assigned only to domain it was set. 不,不可能,cookie仅分配给它设置的域。 You can access it only if domain foo.com send somehow its cookie data to other domain. 仅当域foo.com以某种方式将其cookie数据发送到其他域时,您才能访问它。

It has nothing to do with PHP, this is a browser security setup. 它与PHP无关,这是浏览器的安全设置。 By default, it is not allowed. 默认情况下是不允许的。 The reasons should be obvious. 原因应该很明显。 I wouldn't want anyone to be able to read all my cookies. 我不希望任何人都能阅读我的所有cookie。

However, you can setup something using a cross domain communication channel. 但是,您可以使用跨域通信通道进行设置。 This requires the target domain to grant access to the source domain to read cookies. 这要求目标域授予对源域的访问权限以读取cookie。 This is how Facebook Connect works. 这就是Facebook Connect的工作方式。 This generally involved iframes and javascript on the client side, but the cookie value could be passed to PHP. 这通常涉及客户端上的iframe和javascript,但是cookie值可以传递给PHP。

Here is a write up from MS on the topic. 这是MS关于该主题的文章。 http://msdn.microsoft.com/en-us/library/bb735305.aspx http://msdn.microsoft.com/en-us/library/bb735305.aspx

Try searching on Stack Overflow for 'SSO' for details of how to implement sessions / authentication spanning domains. 尝试在Stack Overflow上搜索“ SSO”,以获取有关如何实现会话/身份验证跨域的详细信息。

C. C。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM