在我的网站和wordpress博客之间共享会话 [英] Share session between my site and wordpress blog

查看:72
本文介绍了在我的网站和wordpress博客之间共享会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在同一域www.mysite.com上的非wordpress网站和wordpress博客之间共享会话,以便当用户登录到我的网站时,他也登录到博客

I would like to know how to share a session between my website non-wordpress and my wordpress blog on the same domain www.mysite.com, so that when a user is logged in to my site he's also logged in to the blog

我在自己的网站上将wordpress安装为子目录,我的网站的网址是www.mysite.com,并且我访问的wordpress就像这样的www.mysite.com/wordpressBlog

I installed wordpress as subdirectory on my site, url for my site is www.mysite.com and I access wordpress like this www.mysite.com/wordpressBlog

在我激活的主站点上的user_login.php中

On my user_login.php in my main site I activated

session_start();

session_start();

激活cookie并在我的wordpress上添加了wp_unregister_GLOBALS()

to activate cookies and on my wordpress wp_unregister_GLOBALS() I added

$ no_unset = array('_SESSION',...

$no_unset = array( '_SESSION', ...

但是什么也没有发生,当我登录到我的主站点时,我仍然必须登录到博客

But nothing happen, when I login to my main site I still have to login to the blog

事实上,我的网站和wordpress博客位于同一个域中.我将wordpress安装为站点的子目录,该站点的URL为www.mysite.com,并且访问了类似www.mysite.com/wordpressBlog这样的wordpress.在我激活的主站点的user_login.php中,

as a matter of fact my site and wordpress blog are on the same domain. I installed wordpress as subdirectory on my site url for my site is www.mysite.com and I access wordpress like this www.mysite.com/wordpressBlog On my user_login.php in my main site I activated

session_start();

激活cookie并在我的wordpress上wp_unregister_GLOBALS()我添加了$ no_unset = array('_SESSION',...

to activate cookies and on my wordpress wp_unregister_GLOBALS() I added $no_unset = array( '_SESSION', ...

但是什么也没有发生,当我登录到我的主站点时,我仍然必须登录到博客

But nothing happen, when I login to my main site I still have to login to the blog

推荐答案

为了能够在两个站点之间共享会话cookie,它们将必须以相同的域名(例如mysite.com)运行.如果会话cookie的范围为mysite.com

In order to be able to share a session cookie between both sites, they will have to run under the same domain name (e.g. mysite.com). The following would be a valid configuration if the session cookie has a scope of mysite.com

www.mysite.com
blog.mysite.com

PS.我不建议使用跨脚本黑客来解决此域范围问题.出于安全原因,它仅限于域.

我还应该指出,托管您的两个子域(站点)是完全有效的在不同的服务器上

I should also point out that it is entirely valid to have your two sub-domains (sites) hosted on different servers

由于您使用的是非WP网站,因此很难为您的问题提供简洁的答案.对于您最好的建议是发布在 WordPress StackExchange 上,您可能会在这里找到曾经做过此配置的人.

It is difficult to provide a succinct answer to your question because you are using a non-WP site. My best suggestion for you is to post on the WordPress StackExchange where you may get someone who has done this configuration before.

我相信您的问题集中在WP中Cookie的范围内. 编辑您的wp-config.php并将COOKIE_DOMAIN设置为使用"可能根据此WordPress StackExchange帖子中提到的问题提供帮助 a>.

I believe your issues are centred around the scope of your Cookie from WP. Editing your wp-config.php and setting the COOKIE_DOMAIN to use "" may help with your issue as referred to by this WordPress StackExchange post.

有些帖子谈到完全取消这种安排.无论如何,您都需要一种调试HTTP会话的方法,以查看使用哪个作用域发送了哪些cookie,这就是我推荐FireBug的原因.无论如何,您仍然必须重新编码您的非WP网站才能识别WP cookie,因此了解正在发生的事情很重要.

Some posts speak of removing this settign entirely. In any case you need a way to debug your HTTP sessions to see what cookies are being sent using which scope, that is why I recommended FireBug. In any case you're still going to have to re-code your non-WP site to recognise the WP cookies so understanding what's going on is important.

我确实碰到过另一篇有关多站点域的文章映射可能有助于您的知识,但这仅涉及WP网站,因此并不完全符合您的需求.

I did come across this other post regarding Multisite Domain Mapping that may help with your knowledge, but this is involved WP sites only so not exactly what you need.

这篇关于在我的网站和wordpress博客之间共享会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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