4

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

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();

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

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();

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

kyserslick
  • 591
  • 1
  • 10
  • 27

1 Answers1

3

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 don't recommend using Cross Scripting hacks to get around this domain scoping issue. It's limited to a domain for security reasons.

[Edit]

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

[Edit]

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.

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.

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.

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.

Community
  • 1
  • 1
Brad
  • 15,186
  • 11
  • 60
  • 74
  • I agree with @brad If not on same domain, do not hack. It's possible to sync usernames with Remote SQL :) – Sibin Grasic Jul 06 '12 at 08:59
  • Does it work also for generic web-apps or are there other approaches to achieve this? @SeeBeen What do you mean whith "Remote SQL"? – davioooh Jul 06 '12 at 09:02
  • Session cookies can be shared by any web app that is on the same domain. By Remote SQL, I mean that you can pull WP user info from WP blog databes on your site. But, if it's on the same domain, you can pull the necessary info locally, without Remote SQL – Sibin Grasic Jul 06 '12 at 09:06
  • 1
    Yes you could synch passwords or use [OpenID](http://openid.net/) to manage your passwords – Brad Jul 06 '12 at 09:07
  • I still need your help please. I am stuck and don't know where to start – kyserslick Jul 06 '12 at 11:25
  • To start, you need to understand how both of your sites define/manage their cookies. This post about [Sharing Session Between Two WordPress Sites](http://wordpress.org/support/topic/share-user-cookie-between-two-blogs-within-same-domain) could be a good start for you. Also install [FireBug](http://getfirebug.com/) for Firefox browser so you can see what cookies are present when you browse a page. Chrome has similar features but I prefer Firebug. – Brad Jul 06 '12 at 13:13
  • Thanks for the quick reply, I already read that post and unfortunatly it didn't help a lot. I have actualy two different user tables structure, one table is for my php website that I use to register people and the other user table is created by wordpress. I know that my php site use's session but wordpress takes cookies instead and I would like to know how to save cookies with login pass once a user is logged in to my site so that I can pass it to wordpress and automaticaly log the user into the blog. – kyserslick Jul 06 '12 at 13:30