Share session between my site and WP blog [closed]

I am using Yii framework for a web site and WP for a blog (don’t ask why, I inherited this project). Yii is responsible for users (login/logout…), and in the blog (WP), I need to know when the user is logged in.

I tried setting session in Yii, $_SESSION['key'] = $value, and reading it in WP, but WP doesn’t see the session: echo $_SESSION['key']

The domain for the site is example.com, and for the blog is example.com/blog.

Is it possible to share a session this way?

1 Answer
1

You can do this in your init or config file.

    ini_set('session.cookie_domain', substr($_SERVER['SERVER_NAME'], strpos($_SERVER['SERVER_NAME'],"."), 100));

Whenever PHP sets the ‘PHPSESSID’ cookie, the cookie will be available to all over the site including Blog.

Leave a Comment