<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>:: TechBlog :: &#187; unified login</title>
	<atom:link href="http://techblog.touchbasic.com/html/tag/unified-login/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.touchbasic.com/html</link>
	<description>Techblog is collection of articles covering a wide variety of tech related topics including: Linux, Microsoft, Google, web development, web design, open source, wordpress, security, and more.</description>
	<lastBuildDate>Thu, 04 Mar 2010 15:51:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Single unified login for multiple WordPress 2.8 installs in subdirectories using cookies</title>
		<link>http://techblog.touchbasic.com/html/single-unified-login-for-multiple-wordpress-2-8-installs-in-subdirectories-using-cookies/</link>
		<comments>http://techblog.touchbasic.com/html/single-unified-login-for-multiple-wordpress-2-8-installs-in-subdirectories-using-cookies/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 16:11:27 +0000</pubDate>
		<dc:creator>elran</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[single login]]></category>
		<category><![CDATA[single sign on]]></category>
		<category><![CDATA[ssi]]></category>
		<category><![CDATA[subdirectories]]></category>
		<category><![CDATA[unified login]]></category>

		<guid isPermaLink="false">http://techblog.touchbasic.com/html/?p=215</guid>
		<description><![CDATA[i used to have a single sign on working between several WordPress sites, one in the root directory, others in subdirectories, even a few installs that ran off of subdomains. basically, you could log in to one site and you&#8217;d be logged into all of these sites. that was before the big upgrade of WP [...]]]></description>
			<content:encoded><![CDATA[<p>i used to have a single sign on working between several WordPress sites, one in the root directory, others in subdirectories, even a few installs that ran off of subdomains. basically, you could log in to one site and you&#8217;d be logged into all of these sites.</p>
<p><em>that was before the big upgrade of WP 2.5 -</em></p>
<p>that&#8217;s right, i&#8217;m sure many out there can remember the chaos that came with upgrading your WordPress blog beyond version 2.5. there was an entirely new backend to get used to, but there were also lots of small code changes that created compatibility issues in many plugins and themes. one of the major changes was the way WordPress was to handle cookies and authentication in general which was made to be more secure. as a result, coders were offered new methods of integrating logins but (at the time) there was little to no clear, accurate documentation detailing how to achieve this task.</p>
<p>i spent many hours last year (with WordPress 2.5 and 2.6), and then again earlier this year (with WordPress 2.7), and then again this weekend (with WordPress 2.8).. until i finally got it working with the help of a relatively new plugin and some new blog posts describing how others attempted this now seemingly daunting task.</p>
<p>anyway, i thought i&#8217;d share my notes as well as the steps i took to get this working with my setup. it&#8217;s currently being used on <a href="http://www.indyish.com/">indyish.com</a> to unify the various WordPress installs into one cohesive multi-user site.</p>
<p>Note: These steps assume you&#8217;ve already got your WordPress sites setup using a shared user database. So, you can log into any of your sites individually with the same credentials, see all the same users under &#8220;Users&#8221; > &#8220;Authors &#038; Users&#8221; &#8211; <strong>but you want to get it so logging into one site automatically logs you into all of your sites</strong>.</p>
<p>Therefore, you have already added the following to the wp-config.php files for any of the sites other than the root site:</p>
<p><code lang="php"><br />
define('CUSTOM_USER_TABLE','wp_users'); // shared user db<br />
define('CUSTOM_USER_META_TABLE','wp_usermeta');  // shared usermeta<br />
</code></p>
<ol>
<li>To start with, you&#8217;re going to need to download and install this plugin: <a href="http://wordpress.org/extend/plugins/root-cookie/">root Cookie Path</a>. Make sure to activate the plugin on all of the sites (the root site, as well as any subdirectory sites).</li>
<li>Once all your sites are using a root cookie, you need to open up the wp-config.php files for any <strong>non-root sites</strong> (ie: subdirectory sites).</li>
<li>Now here&#8217;s the trickier part&#8230; go to your root site (ie: yourdomain.com) and get the following info from your Global Options page: <strong>AUTH_SALT</strong> and <strong>LOGGED_IN_SALT</strong>. You can find the Global Options page for your WordPress install at: http://www.yourdomain.com/wp-admin/options.php (replace &#8220;yourdomain&#8221; with <em>your actual domain</em>)</li>
<li>When you have these 2 values, you need to paste them into the wp-config.php files for <strong>every single non-root site you want to integrate</strong>. Use the following syntax:<br />
<code lang="php"><br />
define('AUTH_SALT', 'some-crazy-wacky-random-long-string-of-characters');<br />
define('LOGGED_IN_SALT', 'some-crazy-wacky-random-long-string-of-characters');<br />
</code></li>
<li>Then, you need to make sure <strong>all of your sites</strong> are using the same &#8220;secret keys&#8221;. Paste that info into the wp-config.php files for each of the <strong>non-root sites</strong> you want to integrate. You can get secret keys fresh from the <a href="https://api.wordpress.org/secret-key/1.1/">WordPress API page</a> if you haven&#8217;t already added them to your wp-config.php file. It should look something like this.<br />
<code lang="php"><br />
define('AUTH_KEY',        'some-crazy-wacky-random-long-string-of-characters');<br />
define('SECURE_AUTH_KEY', 'some-crazy-wacky-random-long-string-of-characters');<br />
define('LOGGED_IN_KEY',   'some-crazy-wacky-random-long-string-of-characters');<br />
define('NONCE_KEY',       'some-crazy-wacky-random-long-string-of-characters');<br />
</code></li>
<li>Finally, add this cookie information to the wp-config.php files for all your <strong>non-root sites</strong>:<br />
<code lang="php"><br />
$baseurl = 'http://www.yourdomain.com'; // replace with the actual domain name for your root site<br />
$cookiehash = md5($baseurl);<br />
define('COOKIEHASH', $cookiehash);</p>
<p>define ('AUTH_COOKIE', 'wordpress_'.COOKIEHASH);<br />
define ('SECURE_AUTH_COOKIE', 'wordpress_sec_'.COOKIEHASH);<br />
define ('LOGGED_IN_COOKIE','wordpress_logged_in_'.COOKIEHASH);<br />
define ('TEST_COOKIE', 'wordpress_test_cookie');<br />
</code></li>
</ol>
<p>That should do it!</p>
<p>Note: Some people have gone ahead and modified the WordPress capabilities.php file in order to get a role assigned to newly registered users, but this step is optional and requires editing a core WordPress file (a change which wouldn&#8217;t persist from one upgrade to another). I prefer to just assign a role manually to any new user that needs access to one of the non-root sites. Or, you could find another trigger to use before calling the function that sets the new role. Still, if you want to go as far as modifying core WP files, here is the code used by <a href="http://kiranthomman.com/setting-single-login-across-multiple-wordpress-27-installs-using-a-single-domain/">Kiran</a>: (but i haven&#8217;t tried it personally)<br />
<code lang="php"><br />
function _init_caps() {<br />
global $wpdb;<br />
// $this->cap_key = $wpdb->prefix . ‘capabilities’; /* original code */<br />
$this->cap_key = ‘wp_capabilities’; /*modified code */<br />
$this->caps = &#038;$this->{$this->cap_key};<br />
if ( ! is_array( $this->caps ) )<br />
$this->caps = array();<br />
$this->get_role_caps();<br />
}<br />
</code></p>
<p>Finally, here are some resources i used to help me out (most recently):</p>
<ul>
<li><a href="http://opensourceexperiments.wordpress.com/2009/02/01/setting-up-a-common-userbase-across-multiple-wordpress-installations/">Setting up a common login across multiple wordpress installations</a></li>
<li><a href="http://kiranthomman.com/setting-single-login-across-multiple-wordpress-27-installs-using-a-single-domain/">Setting single login across multiple WordPress 2.7 installs using a single domain</a></li>
<li><a href="http://www.linickx.com/archives/831/root-cookie-path-14-an-update-for-wordpress-27">root Cookie Path 1.4 an Update for WordPress 2.7</a></li>
<li><a href="http://wordpress.org/extend/plugins/root-cookie/">root Cookie Path</a></li>
</ul>
<p>Here are some other sites (for reference) which i used earlier on this year:</p>
<ul>
<li><a href="http://justintadlock.com/archives/2008/09/20/installing-two-wordpress-blogs-with-the-same-users">Installing two WordPress blogs with the same users</a></li>
<li><a href="http://wordpress.org/support/topic/170987">HOWTO: Set up secret keys in WordPress 2.6+</a></li>
<li><a href="http://boren.nu/archives/2008/07/14/ssl-and-cookies-in-wordpress-26/">SSL and Cookies in WordPress 2.6</a></li>
<li><a href="http://codex.wordpress.org/Editing_wp-config.php#Secret_Key_IMPORTANT">Editing wp-config.php</a></li>
<li><a href="http://codex.wordpress.org/Installing_Multiple_Blogs">Installing Multiple Blogs</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://techblog.touchbasic.com/html/single-unified-login-for-multiple-wordpress-2-8-installs-in-subdirectories-using-cookies/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
	</channel>
</rss>
