Sometime we need to share login session into our subdomains. The user/member will not have to login again in the subdomains.
PHP in general, we usually use
if ( empty(session_id()) ) session_start();
Prefixed with ‘.’ in front of domain, on session.cookie_domain setting.
If familiar with CodeIgniter, just set in the config as
$config['cookie_domain'] = ".domain.tld";
How about in WordPress? It’s also simple, set in your wp-config.php
This session only can be shared into a single WordPress installation. Which mean, if you have other subdomains with another WordPress installation, this configuration might not work, since WordPress has another session for other installation. You have to work around to send your login session into another.
I am not testing yet to share session in the same domain but has different installation. For eg: main site is domain.tld has installation itself and the other, blog.domain.tld also has WordPress installation itself. But will try in another time. If you have experienced with this, please share.
Categorised in: WordPress
This post was written by Sunaryo Hadi