0

I need to share login status across subdomains in one install. For example, after I login in main site: localhost/dx/, but when I visit test.localhost/dx/ (I remove 'redirect_canonical' to stop automatically redirecting to main site), it's the same page, but I'm not logged in. I figured that it's the cookie problem, I tried to set

 define('COOKIE_DOMAIN', '.loclhost'); // or loclhost
 define('COOKIEPATH', '/');  
 define('SITECOOKIEPATH', '/');

but still not remain logged in subdomains.

enter image description here

Anyone has a solution for this?

5
  • Possible duplicate of share login/logout sessions across two installs? Commented Jul 30, 2017 at 11:01
  • I'm afraid not. It's one install and not multisite.
    – Alvin
    Commented Jul 30, 2017 at 12:31
  • then edit your question and include all details. no one here is mind reader Commented Jul 30, 2017 at 13:02
  • .... and obviously you should use multisite. Use wordpress as it is intended to be used and you will delay your heart attack by at least 10 years. Commented Jul 30, 2017 at 13:02
  • There are thousands of subdomains in this project, using mu will create thousands of database tables.
    – Alvin
    Commented Jul 30, 2017 at 13:51

1 Answer 1

-1

You can try like this code:

After installation, open the wp-config.php file in Site B's installation root, and add (or replace) the following lines shortly after the database configuration, modifying them as needed to fit your configuration:

$cookiehash = md5("http://www.example.com/");  // Use Site A's URL

define(CUSTOM_USER_TABLE,'wp_users');           //Change 'wp' to match the prefix set during
define(CUSTOM_USER_META_TABLE,'wp_usermeta');   //  Site A's installation
define('COOKIEPATH', '/');                      //This path should reference Site A's root
define('SITECOOKIEPATH', '/');                  //Should match 'COOKIEPATH'
define('COOKIEHASH', $cookiehash );
1
  • Thanks for the response. I added $cookiehash = md5("localhost/dx/"); // Use Site A's URL define(CUSTOM_USER_TABLE,'sa1x_users'); //Change 'wp' to match the prefix set during define(CUSTOM_USER_META_TABLE,'sa1x_usermeta'); // Site A's installation define('COOKIEPATH', '/'); //This path should reference Site A's root define('SITECOOKIEPATH', '/'); //Should match 'COOKIEPATH' define('COOKIEHASH', $cookiehash ); Now I can't log in. Please note this is not network.
    – Alvin
    Commented Jul 30, 2017 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.