在Wordpress中使用不同子域的相同cookie


Using same cookies with differents subdomains in Wordpress

我有我的主域(http://www.domain.com)它在Wordpress下,我创建了链接类别的子域:

  • http://one.domain.com=>http://www.domain.com/category/one
  • http://two.domain.com=>http://www.domain.com/category/two

它工作得很好,除了持久的cookie。。。我不能使用诸如get_currenterinfo()之类的函数或诸如$user_ID这样的全局变量。

我试过了,但没有成功:

define('COOKIEPATH', '/');
define('COOKIE_DOMAIN', '.domain.com');

你有什么想法吗?非常感谢。

wordpress.org网站提到了不同的cookiepath常量,即

define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) );
define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) );
define('ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );
define('PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL)  );

你已经试过了吗?(当然,你必须设置相应的路径;)

来源:此处