Hey guys, was just wondering how I would go about setting up my Single Sign on with no modules in Drupal 7. I had it running in Drupal 6 but some things were changed in the settings.php file and I'm having a hard time figuring this out.

 You can also use a reference to a schema/database as a prefix. This maybe
 * useful if your Drupal installation exists in a schema that is not the default
 * or you want to access several databases from the same code base at the same
 * time.
 * Example:
 * @code
 *   'prefix' => array(
 *     'default'   => 'main.',
 *     'users'     => 'shared.',
 *     'sessions'  => 'shared.',
 *     'role'      => 'shared.',
 *     'authmap'   => 'shared.',
 *   );
 * @endcode
 * NOTE: MySQL and SQLite's definition of a schema is a database.

This is the code I need to set this up, I just don't know where to put it in my settings.php file. Any ideas?

Comments

hus-’s picture

bump - still have not solved this problem

minnur’s picture

Hi There,

To setup single sign on using no module is simple.

For example you have two sites on the same domain (site1.example.com and site2.example.com)

Lets assume that site1.example.com stores shared data and settings.php for this site is:

$databases['default']['default'] = array (
			'database' => 'db_site1',
			'username' => 'db_multi_user',
			'password' => 'db_multi_password',
			'host' => 'localhost',
			'port' => '',
			'driver' => 'mysql',
			'prefix' => '',
		);
// Read more about this variables in settings.php
$base_url = 'http://site1.example.com';
$cookie_domain = '.example.com';

For site2.example.com settings.php will look like this:

$databases['default']['default'] = array (
			'database' => 'db_site2',
			'username' => 'db_multi_user',
			'password' => 'db_multi_password',
			'host' => 'localhost',
			'port' => '',
			'driver' => 'mysql',
			'prefix' => array(
				'default'   => 'db_site2.',
				'users'     => 'db_site1.',
				'sessions'  => 'db_site1.',
				'role'      => 'db_site1.',
				'authmap'   => 'db_site1.',
				'users_roles'   => 'db_site1.',
			),
		);
// Read more about this variables in settings.php
$base_url = 'http://site2.example.com';
$cookie_domain = '.example.com';

Note that database user should have access to both databases (db_site1 and db_site2)!

phpsharma’s picture

This is great Piece of information!

OLimpikus’s picture

Thanks brohter for the tutorials, but im execute step by step but i cant see single sign on,
im configuring the main and slave sites but dont work sso, in drupal 6 im using similar code in settings, but drupal 7 dont work, im ussing openpublish, Olmpikus

OLimpikus’s picture

Look, the tutorial iis very good, im not shure of how database can connect, and yes need create database for all with same user of database, thanks.

tftaxis’s picture

Hello, how about on different hosts?
I just want to share user datas, content and others will use a local database,

such as:
site1.example.com-->192.168.0.1, with local database db_site1,
site2.example.com-->192.168.0.2, with local database db_site2,

Now I want site2 to use site1's user data, Is that possible? can any one give an example?
Thanks.

sparlez’s picture

I've been burning my eyes reading lots of tutorials that didn't work for D7 and then I found you!!!!!
I did what it is written here and I could log in site2 and site3 with user accounts from site1. the problem was that now site1 was not accepting any login... (I don't know why)
I have erased these lines
$base_url = 'http://site1.example.com';
$cookie_domain = '.example.com';
on site1 settings.php and now it works perfectly on every page.
Thanks again!!!

nvalinski’s picture

This looks like it's exactly what I'm looking for (I have a main site http://example.com and a subsite http://sub.example.com), but I am running into issues with it actually accepting the settings.php. I wipe out the existing settings.php file, run the installation, but the installation ends up getting rid of the 'prefix' values. How were you able to accomplish this without the prefix being wiped out?

ryan_fl’s picture

Will this apply to my site if it is setup as www.example.com (for the main site) and a sub site of www.example.com/training? We have two separate builds of D7 performing 2 separate functions and would like to link the two sites together with just a simple login for the main. Keep in mind I set the sub "/training" site up as a virtual directory in IIS7.

krutibhakta’s picture

Thanks! it works for me.

tftaxis’s picture

Thanks for your sample, now my http://v9zz.com and http://bbs.v9zz.com can share users with this setting. I sitll have some questions, how to share the avatars?

And my http://down.v9zz.com launched on another host, how can I share users with the main site? Thanks, very much.