How to read main cookie from the sub domain with an existing sub domain cookie in PHP?

前端 未结 2 930
花落未央
花落未央 2020-12-18 04:46

I need to use main domain cookies for my sub domains as with higher priority when both sub and main domain cookies exists.

The problem is when I\'m on sub.do

2条回答
  •  暖寄归人
    2020-12-18 05:18

    It looks like the gist of your issue is reading a cookie set in domain.com from sub.domain.com.

    Add

    session.cookie_domain = .domain.com

    to your php.ini to make this happen. If you're on a shared hosting enviroment and can't modify your ini file, try having this somewhere in your code:

    ini_set("session.cookie_domain", ".domain.com");

    You should now be able to access cookies set by domain.com on subdomain.domain.com.

提交回复
热议问题