Cookie - 设置在多个域中 [英] Cookies - set across multiple domains

查看:317
本文介绍了Cookie - 设置在多个域中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的公司设置如下:




  • subdomain1.domain1.com

  • subdomain2 .domain1.com

  • subdomain3.domain1.com

  • subdomain4.domain1.com

  • subdomain5.domain1 .com

  • subdomain6.domain1.com


  • subdomain1.domain2.com

    li>
  • subdomain2.domain2.com

  • subdomain3.domain2.com

  • subdomain4.domain2.com

  • subdomain5.domain2.com

  • subdomain6.domain2.com



在每个网站上,考虑到每个子域可以有一百个网站,用户可以登录。作为开发人员,我们必须在多个浏览器上测试前端,但是一些工作可能只在登录后才需要。 / p>

我写了一个用户脚本,使我们能够保存用户名和密码(以及由于保密性而不能提及的其他细节)。脚本通过填写登录表单并单击提交按钮检查用户帐户是否存在。



在同一个域上的子域之间共享cookie很容易。如果我在subdomain1.domain1.com我可以保存一个cookie,可以通过subdomain2.domain1.com检索。然而,我也想保存这些为domain2。我似乎不能让这个工作。



我可以看到两个解决方案 -



1)使用userscript附加iFrame,这会在domain2上加载网站。然后使用querystring来决定要设置什么,或;



2)使用带有method =POST的表单,



任何一种方式都将是资源密集型的,特别是如果每​​次更改cookie时更新Cookie。我们也有网址掩码。因此,我们还必须考虑像abc.clientdomain1.com,abc.clientdomain2.com等网站。



有没有人知道一个更简单的方法来实现

$ p

解决方案

专为您的Cookie创建公共域,并将其用作getter / setter API。

  http://cookie.domain.com/set/domain1 
http://cookie.domain.com / get / domain1

http://cookie.domain.com/set/domain2
http://cookie.domain.com/get/domain2

等等。


My company has a setup as follows:

  • subdomain1.domain1.com
  • subdomain2.domain1.com
  • subdomain3.domain1.com
  • subdomain4.domain1.com
  • subdomain5.domain1.com
  • subdomain6.domain1.com

  • subdomain1.domain2.com

  • subdomain2.domain2.com
  • subdomain3.domain2.com
  • subdomain4.domain2.com
  • subdomain5.domain2.com
  • subdomain6.domain2.com

On each site, bearing in mind there can be a hundred sites per subdomain, users can log in. We, as developers, have to test frontends across several browsers, but some work may only be required on a section once logged in.

I have written a userscript which enables us to save a username and password (and other details which I cannot mention because of confidentiality). The script checks to see if the user account exists by filling in the login form and clicking the submit button. If not, it registers for us - thus automating the registration process.

Sharing cookies between subdomains on the same domain is easy. If I am on subdomain1.domain1.com I can save a cookie which can be retrieved by subdomain2.domain1.com. However, I would also like to save these for domain2. I do not appear to be able to get this to work.

I can see two solutions from here - either:

1) attach an iFrame using the userscript, which loads a site on domain2. This then uses the querystring to decide what to set to what, or;

2) use a form with method="POST", and simply post to a file on each domain.

Either way will be resource intensive, particularly if the cookies are updated each time a cookie changes. We also have URL masking in place. So we'd also have to take into account sites like abc.clientdomain1.com, abc.clientdomain2.com etc.

Does anyone know of an easier way to do achieve this?

解决方案

Create a common domain specifically for your cookies and use it as a getter/setter API.

http://cookie.domain.com/set/domain1
http://cookie.domain.com/get/domain1

http://cookie.domain.com/set/domain2
http://cookie.domain.com/get/domain2

and so on.

这篇关于Cookie - 设置在多个域中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆