Drupal 7 Single Sign on using settings.php
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 开发者_如何学GoSQLite'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?
My setting.php file look like this :
$databases = array (
'default' =>
array (
'default' =>
array (
'driver' => 'mysql',
'database' => 'drupal7',
'username' => 'toto',
'password' => 'xxxxxxxxxxxxxxx',
'host' => 'localhost',
'port' => '',
'prefix' => array(
'default' => '',
'users' => 'drupal7_common.',
'sessions' => 'drupal7_common.',
'role' => 'drupal7_common.',
'authmap' => 'drupal7_common.',
'languages' => 'drupal7_common.',
'locales_source' => 'drupal7_common.',
'locales_target' => 'drupal7_common.',
),
),
),
);
The Drupal 7 style for database configuration is like so:
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'd7',
'username' => 'drupaluser',
'password' => '',
'host' => '127.0.0.1',
'port' => 33066,
'prefix' => array(
'node' => 'foo_',
)
);
Based on documentation:
- http://api.drupal.org/api/drupal/includes--database--database.inc/7/source
- http://api.drupal.org/api/drupal/includes--database--database.inc/function/DatabaseConnection::prefixTables/7
- http://drupal.org/node/310072
I tested it locally and it seems to work as expected.
Allow me to add a bit more detail using the following settings.php file entry:
$my_db_users = 'dbusers.shared_';
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'dbdefault',
'username' => 'databaseuser',
'password' => 'databasepassword',
'host' => '127.0.0.1',
'port' => 3066,
'prefix' => array(
'default' => 'default_',
'users' => $my_db_users,
'sessions' => $my_db_users,
'role' => $my_db_users,
'authmap' => $my_db_users,
),
'collation' => 'utf8_general_ci',
);
In the above instance, we have set a variable $my_db_users
to be equal to the database and table prefix of the location of the shared user data.
We then set the default table prefix 'default' => 'default_',
which says: "store all tables, unless otherwise specified, in defaultdatabase and make their table prefix default_." We're also saying: "store all users, sessions, roles, and user-role mappings (authmap) in the database dbusers with the table prefix shared_."
A slight twist:
Consider removing the 'authmap' => $my_db_users,
line. If you do this you could have the same users and groups accross a large network of sites while still allowing users different permissions on different sites. On one site you may be an administrator, but on another you'd be an author.
For signing on multiple sites with same login credentials you need to make some changes in drupal setting.php file.
Here's a nice tutorial for this functionality: http://drupixels.com/blog/single-sign-drupal-7
精彩评论