Deprecated: Assigning the return value of new by reference is deprecated in D:\kiranthomman.com\wwwroot\wp-settings.php on line 264

Deprecated: Assigning the return value of new by reference is deprecated in D:\kiranthomman.com\wwwroot\wp-settings.php on line 266

Deprecated: Assigning the return value of new by reference is deprecated in D:\kiranthomman.com\wwwroot\wp-settings.php on line 267

Deprecated: Assigning the return value of new by reference is deprecated in D:\kiranthomman.com\wwwroot\wp-settings.php on line 284

Deprecated: Assigning the return value of new by reference is deprecated in D:\kiranthomman.com\wwwroot\wp-includes\cache.php on line 36

Deprecated: Assigning the return value of new by reference is deprecated in D:\kiranthomman.com\wwwroot\wp-includes\query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in D:\kiranthomman.com\wwwroot\wp-includes\theme.php on line 540
Kiran Thomman » Blog Archive » Setting single login across multiple Wordpress 2.7 installs using a single domain

Setting single login across multiple Wordpress 2.7 installs using a single domain

I am in the process of launching a community website. It’s requires different sections including a forum. The best way of handling it was to use different instances of Wordpress for each section. This way I could use separate themed templates for each install. Although each section especially the forum would have its own unique set of visitors some of them tend to be shared across the other sections. It really wouldn’t appeal to visitors to login or register to each section separately to each section of the site. So ideally the user profile has to roam across all sections of the site using a single registration or login from any section.

A quick search on Google revealed that its possible. Most of the posts I researched were helpful put could only partially solve the problem. The first post Setting up a common login across multiple wordpress installations claimed to solve the issue only helped me in allowing the different sections to use the same login as the main site. The reason it probably  worked for the writer was that the other steps too were incorporated earlier but not for the specific purpose of a common login which he did not consider. The second post Multiblog single login in WP 2.6 gave an idea as to how it could be accomplished but in 2.6. However it is the final post Múltiples (WordPress + bbPress + MediaWiki) en uno that actually helped me and covered all the steps but this is in Spanish and I had to use Babelfish to understand what he was sharing. So the pupose of this post is to provide an english version of the last post or probably a summation of all three as I feel this is something that could come in very useful to other wordpress blog users who would want to do something similar.

I am not a hardcore Wordpress user and this personal blog is the only one I have formally worked on till now. So I am a novice to the whole thing. I’m telling you this to let you know that its not a big deal to get it all working when the people and posts above have enlightened you on how to go about it.

Although my actual url is different I am testing temporarily using my site kochidaily.com. And for the purpose of explanation we will be using this website. The first step is to install the multiple Wordpress blogs. I have now set up two blogs one accessible at www.kochidaily.com and the other at www.kochidaily.com/jobs . Both the blogs use a single database. However at the time of install I have set the prefix of the table for the main database as cd_ and the jobs database as jobs_. After this I ended up with two blogs with independent logins.

The next step is for www.kochidaily.com/jobs to use the same login as the main site www.kochidaily.com. This was accomplished by editing two files in the second blog ie is the jobs. First I edited wp-config.php after the line /* That’s all, stop editing! Happy blogging. */
with

define(’CUSTOM_USER_TABLE’, ‘cd_users’);
define(’CUSTOM_USER_META_TABLE’, ‘cd_usermeta’);

After this I opened capabilities.php in wp-includes and modified the section after Setup capability object properties to

function _init_caps() {
global $wpdb;
// $this->cap_key = $wpdb->prefix . ‘capabilities’; /* original code */
$this->cap_key = ‘cd_capabilities’; /*modified code */
$this->caps = &$this->{$this->cap_key};
if ( ! is_array( $this->caps ) )
$this->caps = array();
$this->get_role_caps();
}

After this I was able to log in to both blogs using the logins from the main site but had to login and logout individually.

Now I have to share logins across both sites this is achieved by making the cookie information across sites is the same. In the wp-config file I navigated to the section specifying Authentication Unique Keys. I generate unique keys by using the URL https://api.wordpress.org/secret-key/1.1/ as specified in that section. I replace the authentication keys for all wp-config files with the same lines so that they remain the same for each blog. My final lines for wp-config placed under authentication keys is as follows.

define (’COOKIE_DOMAIN’, ‘.kochidaily.com’);
define(’COOKIEPATH’, ‘/’);
define(’AUTH_KEY’, ‘j7z/~e9,G3=WY*plq^2b9_E1qgf-N< dxJD>)]+J5-[v’);

define(’SECURE_AUTH_KEY’, ‘unt&N4$hw;qmt3VEY*_=(7-3N)*9[~v4–Y#s*k&fqsR7va*h}WHyQAwf{=+;?C-’);

define(’LOGGED_IN_KEY’, ‘B%K&JbF?_=Ft6N`WvZ+&*SbW::x8AhNL5_Gs$/(oAsLY1,D1JlaF#a$/DRNfy[qV’);

define(’NONCE_KEY’,  ‘KFOYq&kB[D?2J~ ;W:zSbn#$hDm{_6<p|T^/}1d4^%N HC7m3jc[-|(38~ |P+lh’);

$baseurl = ‘http://www.kochidaily.com’;
$cookiehash = md5($baseurl);
define(’COOKIEHASH’, $cookiehash);
define (’AUTH_SALT’,'AUTH_SALT’.COOKIEHASH);
define (’LOGGED_IN_SALT’, ‘LOGGED_IN_SALT’.COOKIEHASH);
define (’AUTH_COOKIE’, ‘AUTH_COOKIE’.COOKIEHASH);
define (’SECURE_AUTH_COOKIE’, ‘SECURE_AUTH_COOKIE’.COOKIEHASH); // If you use connection SSL
define (’LOGGED_IN_COOKIE’,'LOGGED_IN_COOKIE’.COOKIEHASH);
define (’TEST_COOKIE’, ‘TEST_COOKIE’.COOKIEHASH);

As you can see there are other cookie values than what you see by default. This too needs to be shared so I appended it below the shared Authentication keys in order for the logins to be shared. I have used an md5 of $baseurl which is set to the site name you can modify it to any phrase of your choice. Well thats it I fired my browser cleared all cookies previously set (for testing) I logged into the main site and then shifted to the jobs site and voila! I was logged in there too!

Email This Post Email This Post

8 Responses to “Setting single login across multiple Wordpress 2.7 installs using a single domain”

  1. Fernando Tellado Says:

    Thanks for the link Kiran.

    You have an automatic translation of our post if you like:

    http://ayudawordpress.com/en/multiples-wordpress-bbpress-mediawiki-en-uno/

  2. adrenalini Says:

    Hi! Thank you for the instruction. Still, it doesn’t quite suit me, because I’m using separate databases for blogs (domain.com uses one database, sub1.domain.com - another etc.).

    Any ideas how to share auth cookies in such situations?

  3. Ray Says:

    Hi Kiran,

    I tried your technique on our site.

    I get the right cookie names, but the values are different for “LOGGED_IN_COOKIE” and “AUTH_COOKIE”.

    Which means I still have to login to both WP blogs. No single sign on for me!

    TEST_COOKIE is the only one with the same value.

    Any idea why?

  4. admin Says:

    Sorry for the late reply was busy with my newborn son’s homecoming (In India the mother leaves for her parents home for delivery and returns only three months after the baby is born) Sorry for the late reply.

    Also Id like to confess I’m not very good at programming its just that I just applied plain logic from various sites as mentioned to arrive at the above so I am not an expert. But if you still haven’t sorted it out.

    Adrenalini - Is there any specific benefit for you for running different databases? If not merge them into a single one. And try it ( on a standalone WAMP or LAMP local server). It should work (I think!)

    Ray- After modifying the capabilities file are you able to login with the main sites login in the other site? What version of Wordpress are you using? It has to work. Try clearing your cache it must be the issue.

  5. Ray Says:

    Hey Kiran,

    How are you testing your single sign on?

    Are you going to www.kochidaily.com/wp-admin/ to login?
    And then after you have successfully logged in, do you go to www.kochidaily.com/jobs/wp-admin/ to see if you’re logged in there as well?

    Also I noticed that you’re using a different capabilities hack than I am.

    This is the one I’m using:
    http://wordpress.org/support/topic/164758?replies=13#post-915630

  6. admin Says:

    Yes, thats exactly how I test single login. Could you try using the capability hack that I use. Although the only difference I see in both is that Im specifying my capabilities table whereas the post you have used takes it off the settings given on the website. Also there are some other things which I have added in my capabilities. Please note that the post you are reading is for Wordpress 2.5. I think mine works well in 2.7 so you should add the additional lines I have given or try using the hack Iv used. You will have to mod it for your variables for table name.

    In case it still doesn’t work could you paste the capabilities hack you are using along with the capabilities table name of your main site or table whose login you are using? the taffele site which suggests integration is already mentioned in my blog however it may work for 2.6 dunno about 2.7.

  7. Patung Says:

    I’ve found that this gets broken in 2.8…basically if I define

    define(’COOKIE_DOMAIN’, ‘.domain.com’);
    define(’COOKIEPATH’, ‘/’);

    in wp-config I am unable to access wp-admin on one of my installs. I am actually logged in there but just can’t access the admin section. Removing those two lines lets me back into admin…

  8. Lew A Says:

    I had to do something similar, this was my solution:
    http://fullthrottledevelopment.com/setting-a-single-login-across-wp-wpmu

    For WP 2.8.1 and WPMU 2.8.1

    Lew

Leave a Reply