简体   繁体   English

仅从一个网站接受Cookie:PHP

[英]Accept Cookies from One Website only : PHP

I was wondering if there was a way in PHP to accept cookies from only the original website. 我想知道PHP是否有一种方法可以仅接受原始网站的cookie。

For Example: 例如:

I set a cook when a visitor come to my website www.example.com, now when they come from a website like Microsoft Translator to view my website that cookie is set with the web address of Microsoft. 当访问者访问我的网站www.example.com时,我会做饭。现在,当访问者来自诸如Microsoft Translator之类的网站来查看我的网站时,即使用Microsoft的网址设置了cookie。 I then only want to get cookies from my website example.com and not allow the cookie to work if visiting my site through Microsoft Translator. 然后,我只想从我的网站example.com获取cookie,并且如果通过Microsoft Translator访问我的网站,则不允许该cookie工作。

I hope this make sense. 我希望这是有道理的。 Thanks in advance. 提前致谢。

You're misunderstanding how cookies work - cookies are ALWAYS set only for the domain from which they originate. 您误解了Cookie的工作原理-Cookie始终仅针对其来源域设置。 It's a violation of the cookie spec to allow a site to set a cookie for a domain other than itself - think of what would happen if "nastysite.com" were able to set a cookie for "yourbank.com"? 允许站点为自身以外的域设置cookie违反了cookie规范-想想如果“ nastysite.com”能够为“ yourbank.com”设置cookie会发生什么?

Perhaps you're thinking of the REFERER, which (if it's available) can point back to the address of the page the user came from. 也许您在考虑REFERER,它可以(如果有的话)指向用户所在页面的地址。

However, that can't affect the cookies on your site, unless you yourself are placing any of that referer information into the cookie. 但是,这不会影响您网站上的Cookie,除非您自己将任何引荐来源信息放入Cookie中。 If you don't want users who came in from Microsoft Translator to get a cookie, then you have to check the REFERER and simply not set the cookie if they did. 如果您不希望来自Microsoft Translator的用户获得cookie,则必须检查REFERER并简单地不设置cookie(如果他们这样做了)。

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

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