简体   繁体   English

两个cookies同名但域名略有不同? 我如何使用 JS 访问它们

[英]Two cookies with the same name but slightly different domain name? How do i access them with JS

So there are two cookies, one under "www.mywebsite.com" and the other under "mywebsite.com" so after some testing i managed to figure out the latter is for logins to my site and the former is just like, whenever anyone visits the site I think (or something along those lines, I don't know the specifics.所以有两个 cookies,一个在“www.mywebsite.com”下,另一个在“mywebsite.com”下,所以经过一些测试后,我设法弄清楚后者是用于登录我的网站,而前者就像任何人一样访问我认为的网站(或类似的东西,我不知道具体情况。

At any rate, they are both named xxxx, and when I try to access them I am given the one from www.mywebsite.com and I need the other one, how can I change which cookie is accessed in javascript/jquery?无论如何,它们都被命名为 xxxx,当我尝试访问它们时,我从 www.mywebsite.com 获得了一个,而我需要另一个,如何更改在 javascript/jquery 中访问的 cookie?

If the cookie is written to a specific subdomain, then that cookie can only be accessed by that particular subdomain.如果 cookie 被写入特定的子域,则该 cookie 只能由该特定子域访问。

Cookies set for .mywebsite.com can be accessible at www.mywebsite.com , but not vice versa. Cookies 设置为.mywebsite.com可以在www.mywebsite.com访问,但反之则不行。

since www is a subdomain you need to be on that subdomain to access that cookie.由于www是一个子域,因此您需要在该子域上才能访问该 cookie。 So it seems your cookies as subdomain based.因此,您的 cookies 似乎是基于子域的。

if you want the non-subdomain one you need to move your document location to mywebsite.com without that subdomain.如果您想要非子域,则需要将文档位置移动到没有该子域的 mywebsite.com。

and you'll better use global cookies next time and make their names unique下次你最好使用全局 cookies 并使其名称独一无二

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

相关问题 两个服务器,相同的域名,无法获取cookie - Two servers, same domain name, can't get cookies 如何在不同的js文件中处理两个具有相同名称的变量? - How to deal with two variables with the same name in different js files? 在Firefox扩展程序中按域名/名称访问特定的cookie - Access specific cookies by domain/name in Firefox extension 是否可以为两个不同的网页设置相同的DOMAIN NAME? 如果是的话,如何实现? - Is it possible to have the same DOMAIN NAME for two different webpages? If yes, how can it be achieved? 如何访问具有 5 个同名变量的 json 值 - How do i access to a json value with 5 variables with the same name 如何访问具有相同类名的元素的数据属性? - How do I access data attribute of elements with the same class name? 删除具有相同名称但路径不同的cookie - Removing cookies with the same name but different paths 用域路由管理同一个域名下的两个不同的Azure资源 - Managing two different Azure resources under the same domain name with domain routing 如何访问vue js应用程序中的域名? - How to access to domain name inside vue js application? 在不同的.js文件中使用两个同名的方法 - Use two methods of the same name in different .js files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM