Share login datacookies between multiple installations

admin2025-01-08  4

I have a WordPress installation at the document root for a domain, and then an additional installation in an immediate subdirectory of that installation such that I may use different themes for the two. I want to link the two sites logins so that you don't have to login twice in order to use both sites.

My coding skills are not great, so an easy fix or an of the shelf plugin are preferred.

I have a WordPress installation at the document root for a domain, and then an additional installation in an immediate subdirectory of that installation such that I may use different themes for the two. I want to link the two sites logins so that you don't have to login twice in order to use both sites.

My coding skills are not great, so an easy fix or an of the shelf plugin are preferred.

Share Improve this question edited Jan 27, 2014 at 21:24 bosco 7,0043 gold badges28 silver badges47 bronze badges asked Jan 27, 2014 at 20:48 JasonJason 611 gold badge1 silver badge2 bronze badges 5
  • Are you talking about a subdomain, or simply a sub-directory? A subdomain would be something along the lines of subdomain.bradleycountypulse.com, but all you mention is the /classifieds sub-directory (or URL component). Assuming that both URLs use the same WordPress installation and same database, there is no reason that the two would not already share the same login session... Have you installed WordPress twice? Is there any reason that you need to have two separate WordPress installations? – bosco Commented Jan 27, 2014 at 20:54
  • Playing around with your linked site, it appears to me as though you do indeed have two seperate WordPress installations - one located at bradleycountypulse.com and the other at bradleycountypulse.com/classifieds. Or is this a single multisite installation? – bosco Commented Jan 27, 2014 at 20:57
  • I had to use two installs because of the unique features of the classifieds page, a special theme was needed. – Jason Commented Jan 27, 2014 at 20:59
  • I wanted to use the sahifa theme for the main site, and then have classifieds pick up after clicking that link – Jason Commented Jan 27, 2014 at 21:01
  • In the event you need multiple sites for, e.g., a company intranet that needs to share logins, the Google Apps Login plugin is perfect (if your company uses Google Apps, o' course). – Ryan Commented Feb 8, 2016 at 22:33
Add a comment  | 

2 Answers 2

Reset to default 5

You can share user tables between different WordPress installations by installing the second site ("Site B") to use the original site's ("Site A") database, then choosing to use an alternate table prefix during installation so as to keep the rest of the data separate.

The second part of the problem is sharing login cookies between the two installations (what WordPress uses to keep track of login/"session" data). In order to do this, you must use the same cookie-path for both sites.

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.bradleycountypulse.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 );

Note that this will only work if the two installations reside on the same domain (which yours do!).

An alternate solution would be to setup the entire system as a single multisite installation.

Still another solution (albeit one that requires more legwork) would be to employ custom page templates on a single installation.

I have released a wordpress plugin based on the following article:

http://subinsb.com/set-same-cookie-on-different-domains

User Session Synchronizer allows you to keep the user logged in from one wordpress to another by synchronizing user data and cookie session based on a verified email.

The user email is encrypted based on the current user ip and a secret key shared by the synchronized wordpress installations.

You can find the plugin here:

https://wordpress.org/plugins/user-session-synchronizer/

And participate here:

https://github.com/rafasashi/user-session-synchronizer

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

最新回复(0)