login - How to stay logged in on a multisite with different domains?

admin2025-01-07  5

I understand that, if I use subdomains on a multisite, then WordPress has the built in function of keeping the users logged in.

The different domains are a must. These sites were set up using the built in "add a new site" feature of WordPress. (I did not use a plugin to set up the sites.) The sites work fine as they are, except I would like for a user who signs into abc be able to switch to def to still be logged in.

I have tried adding define('COOKIE_DOMAIN', ''); to my wp-config file.

Also I've tried.

define('ADMIN_COOKIE_PATH', '/');
define('COOKIE_DOMAIN', '');
define('COOKIEPATH', '');
define('SITECOOKIEPATH', '');

and I've tried changing define('SUBDOMAIN_INSTALL', true); between true and false. I've tried as many variations of the above as I can think of. The only other solution I've seen mentioned was a SSO plugin which would allow users to use their google or Facebook logins to sign in, but we are not comfortable with this option.

(A note: When I looked this issue up, some people were getting error messages about cookies not working/not being allowed and I have not noticed any error messages to that effect.)

I understand that, if I use subdomains on a multisite, then WordPress has the built in function of keeping the users logged in.

The different domains are a must. These sites were set up using the built in "add a new site" feature of WordPress. (I did not use a plugin to set up the sites.) The sites work fine as they are, except I would like for a user who signs into abc.com be able to switch to def.com to still be logged in.

I have tried adding define('COOKIE_DOMAIN', ''); to my wp-config file.

Also I've tried.

define('ADMIN_COOKIE_PATH', '/');
define('COOKIE_DOMAIN', '');
define('COOKIEPATH', '');
define('SITECOOKIEPATH', '');

and I've tried changing define('SUBDOMAIN_INSTALL', true); between true and false. I've tried as many variations of the above as I can think of. The only other solution I've seen mentioned was a SSO plugin which would allow users to use their google or Facebook logins to sign in, but we are not comfortable with this option.

(A note: When I looked this issue up, some people were getting error messages about cookies not working/not being allowed and I have not noticed any error messages to that effect.)

Share Improve this question edited Apr 27, 2018 at 18:55 Pat J 12.3k2 gold badges28 silver badges36 bronze badges asked Apr 26, 2018 at 22:38 Kaye O'MalleyKaye O'Malley 215 bronze badges 3
  • Have you tried this answer? – Aurovrata Commented Apr 27, 2018 at 7:32
  • it didn't work. I logged into the main domain and when I switched to a different one it asked me to log in again. – Kaye O'Malley Commented Apr 28, 2018 at 19:42
  • its important when you change cookie settings to clear your cache properly before testing any changes as your previous cookie will be cached. Keep in mind also that if you already have a live version of a website and you are upgrading the cookie settings to change your salt keys. this will ensure that previous visitors browsers will refresh their cookies. – Aurovrata Commented May 1, 2018 at 8:26
Add a comment  | 

1 Answer 1

Reset to default 0

I added this to my wp-config.php file:

define('COOKIE_DOMAIN', '.example.com');
define('COOKIEPATH', '/');
define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . md5('https://example.com'));
define('AUTH_COOKIE', 'wordpress_' . md5('https://example.com'));

Tip: Logout first, or you might have to delete all your browser cookies. Hope this helps.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736256099a334.html

最新回复(0)