0

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?

FamousWolluf
  • 568
  • 1
  • 3
  • 25
  • you can persist your sessions in database with help of SessionHandler i wrote a full description https://stackoverflow.com/questions/54514033/php-sessions-keep-timing-out/54514199#54514199 – Ali Ghalambaz Feb 08 '19 at 10:13
  • I've looked in to it, and have tried it. But every subdomain creates it's own session_id in the database. So how must the other subdomain know witch session to use, because right now it creates his own session – FamousWolluf Feb 08 '19 at 13:30
  • i was wrong! sorry – Ali Ghalambaz Feb 08 '19 at 16:54

1 Answers1

2

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

Ali Ghalambaz
  • 420
  • 3
  • 7