将 wordpress 会话扩展到主域 [英] extend wordpress session into main domain

查看:28
本文介绍了将 wordpress 会话扩展到主域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将 wordpress 用于社区目的的站点,它安装在子目录mysite/community"下,但是当我尝试将 wordpress 函数调用到mysite"中时,我无法检索已登录的用户.

I have a site that uses wordpress for community purposes, it is installed under subdirectory "mysite/community" but when I try to call wordpress functions into "mysite" I cannot retrieve the logged user.

这是我的示例代码:

require $xcart_dir . DIR_COMMUNITY . '/wp-load.php';

wp_get_current_user();
if ( 0 == $current_user->ID ) {
    echo "Not logged in";
} else {
    echo "Logged in";
}

推荐答案

Cookies 可以包含一个 Path,这可能就是你要找的:http://codex.wordpress.org/Editing_wp-config.php#Additional_Defined_Constants

Cookies can contain a Path, this is probably what you are looking for: http://codex.wordpress.org/Editing_wp-config.php#Additional_Defined_Constants

要允许域上所有路径的 cookie,请使用 define('COOKIEPATH',"/");.

To allow the cookie for all path on the domain, use define('COOKIEPATH',"/");.

您也可以在 wp-config.php 中设置 cookie 域:http://codex.wordpress.org/Editing_wp-config.php#Set_Cookie_Domain

You can also set the cookie domain in wp-config.php: http://codex.wordpress.org/Editing_wp-config.php#Set_Cookie_Domain

使用 ".example.com" 允许 example.com 的所有子域的 cookie.

Use ".example.com" to allow the cookie for all subdomains of example.com.

这篇关于将 wordpress 会话扩展到主域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆