Share cookie between subdomain and domain

前端 未结 7 1783
伪装坚强ぢ
伪装坚强ぢ 2020-11-21 13:58

I have two questions. I understand that if I specify the domain as .mydomain.com (with the leading dot) in the cookie that all subdomains can share a cookie.

相关标签:
7条回答
  • 2020-11-21 14:25

    Be careful if you are working on localhost ! If you store your cookie in js like this:

    document.cookie = "key=value;domain=localhost"
    

    It might not be accessible to your subdomain, like sub.localhost. In order to solve this issue you need to use Virtual Host. For exemple you can configure your virtual host with ServerName localhost.com then you will be able to store your cookie on your domain and subdomain like this:

    document.cookie = "key=value;domain=localhost.com"
    
    0 讨论(0)
提交回复
热议问题