在主域上取消设置后,会话变量不会在子域上取消设置

问题描述:

我已经设置好,所以我可以在主域和子域之间共享会话数据,在我使用代码的子域脚本上:

I have it setup so I can share session data across the main domain plus a subdomain, on the subdomain script I am using the code:

ini_set('session.cookie_domain', COOKIE_DOMAIN);

session_start();

COOKIE_DOMAIN 等于 .domain.com

使用此代码后,会话在子域上显示良好,但是当它们通过以下代码在主域上未设置时:

Sessions show up fine on the sub-domain after using this code, however when they are unset on the main domnain via code like:

unset($_SESSION[SESSION_PREFIX.$variable]);

它们在主域上未设置,但在子域上未设置.

They get unset on the main domain but not the sub-domain.

修复是将它设置在您的 php.ini 中..

Fix was to set it in your php.ini instead..

session.cookie_domain = ".mydomain.com"