Reputation: 578
I have multiple subdomains and they all use the same database with the same user table.
When I login to a.domain.com I want also to be logged in to b.domain.com, etc.
I've found multidomain-sso (https://github.com/0k/multidomain-sso) but our problem is that we can have up to 100 subdomains, and I'm afraid that the approach of mutlidomain-sso will slow the login process, because it visits every subdomain through AJAX.
How can I login to one subdomain and be logged in to the other 100 subdomains also?
Upvotes: 0
Views: 1460
Reputation: 420
login is based on cookie and session data . you need to set php session id(PHPSESSID) to set in a cookie with main domain. you can login in main domain or set your cookie to access your domain and subdomains.
$currentCookieParams = session_get_cookie_params();
$rootDomain = '.example.com';
session_set_cookie_params(
$currentCookieParams["lifetime"],
$currentCookieParams["path"],
$rootDomain,
$currentCookieParams["secure"],
$currentCookieParams["httponly"]
);
session_name('mysessionname');
session_start();
setcookie($cookieName, $cookieValue, time() + 3600, '/', $rootDomain);
?>
Upvotes: 2