Share cookie between subdomain and domain

前端 未结 7 1784
伪装坚强ぢ
伪装坚强ぢ 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:22

    Simple solution

    setcookie("NAME", "VALUE", time()+3600, '/', EXAMPLE.COM);
    

    Setcookie's 5th parameter determines the (sub)domains that the cookie is available to. Setting it to (EXAMPLE.COM) makes it available to any subdomain (eg: SUBDOMAIN.EXAMPLE.COM )

    Reference: http://php.net/manual/en/function.setcookie.php

提交回复
热议问题