Sharing User Information

The idea of an online community can be greatly enhanced if the community spans multiple sites. One problem that plagues the Internet in this respect is the requirement that visitors must log in to every site they visit, often with different usernames and passwords. With database prefixing, you can sidestep part of this problem by allowing your visitors to use the same username and password for multiple sites. Listing 6-3 shows the $db_prefix definition that makes this possible.

Listing 6-3. Sharing User-Related Tables $db_prefix = array(

default'

=>

'site ',

users'

=>

'shared

sessions'

=>

'shared

role'

=>

'shared

authmap'

=>

'shared

sequences'

=>

'shared

To share user information, follow these steps:

1. Use prefix.sh to create a new database definition file called shared.mysql with the shared_ prefix. All you really need are the definitions for the six shared_ tables from Listing 6-3. The rest of the table definitions can be deleted.

2. For every site that you want to share usernames and passwords, run prefix.sh again to create database definition files that each has a unique prefix that corresponds to an individual site.

3. Import all of the database definitions into the same database.

4. For each site, you will need a separate subdirectory in the sites folder, as described earlier in this chapter.

5. For each site, update settings.php with the code from Listing 6-3 for the $db_prefix variable. Update the value given for 'default' to match the prefix of the particular site.

â– Caution Sharing tables between sites has profound effects in terms of how your sites behave, and some combinations of table sharing will lead to data inconsistency and broken sites. It is a technique that is recommended only for advanced users who are intimately familiar with the inner workings of Drupal.

Was this article helpful?

0 0

Post a comment