News:

Wondering if this will always be free?  See why free is better.

Main Menu

Share user database for 2 (or more) different forums.

Started by Spaceman-Spiff, September 03, 2004, 09:14:44 PM

Previous topic - Next topic

Spaceman-Spiff

Someone asked me how to setup 2 different SMF forums with shared user database. So, instead of writing in private message, I decide to share it here. Besides, I have never tried this myself, so I could use the feedback in case the steps I outline below are wrong or incomplete.

In the tutorial below, the following database tables will be shared:

  • im_recipients
  • instant_messages
  • membergroups
  • members
You can share more tables if you like, and if you know what you're doing.

Here it goes...

1. Installing the forums
Install two (or more) different SMF forum in the same database, but using different prefix. For this example, the first forum is using "smf1_" (without quotes) and the second is using "smf2_". Just install the two forums normally, don't start telling users to sign up yet.


2. Modifying the source code
Open each of the .php files located in the Sources directory in your hard drive using a text editor program. Find all occurances of "{$db_prefix}members" and replace with "smf1_members" (without quotes). Do this for every single .php file in the Sources directory. Also find and replace the following:
"{$db_prefix}im_recipients" => "smf1_im_recipients"
"{$db_prefix}instant_messages" => "smf1_instant_messages"
"{$db_prefix}membergroups" => "smf1_membergroups"
You can also share more tables if you want and know what you're doing.

If you have a text editor program that can do batch replace or replace in all opened documents, use that instead, it will ease the task a lot (you can open everything at do a replace for all of the opened files). One text editor program that I know can do this is JCreator.


3. Upload the modified source files
Upload the content of the Sources directory that you just modified above to the Sources directory in your forum(s), overwrite any existing files. You don't need to do this for your first forum (smf1_), but doing this won't cause any problems.

Your forums should now share the same member, membergroup and instant message database.


4. Optional settings
If both (or all) of the forums are hosted on the same site (domain), you can use the same Cookie name for SMF, so users won't need to login twice when moving from one forum to another. You can find this setting inside the Admin Center -> Edit Server Settings -> Cookie Name


Possible Issues

  • User uploaded avatar
    Temporary solution: disable this feature.
    Better solution: also share the "attachments" table and synchronize the attachment settings (Admin Center -> Edit Features and Options -> Attachments section). This probably won't work if the forums are in different domains or subdomains.
  • Forum with multiple themes (ID_THEME conflict in members table)
    Temporary solution: use the same themes, or set the default forum theme for all of the forum using the same ID, and don't let users select their own theme.
  • Show unread may not work when moving from one forum to another
    You should edit in the templates and replace the link to "action=unread" to "action=unread;all;start=0". What this does is show all unread posts by that user.


Other recommended tables to share:
- log_karma
- log_online <- session might get screwed if the forums are in different domains


Any comments/suggestions/errors?
I keep on thinking I'm forgetting something here... ::)

[Unknown]


nil

What if its in the format: ' . $db_prefix . '

Such as how do I change this line to point at smf_roster?
$qrycr = mysql_query('SELECT `membergroup`,`ACCTUSER` FROM ' . $db_prefix . 'roster WHERE ACCTUSER=\'' . $user_info[username] . '\'')

Thanks this will solve a huge problem on one of my forums!

[Unknown]

Find:

$qrycr = mysql_query('SELECT `membergroup`,`ACCTUSER` FROM ' . $db_prefix . 'roster WHERE ACCTUSER=\'' . $user_info[username] . '\'');

Replace:

$qrycr = mysql_query('
SELECT membergroup, ACCTUSER
FROM smf_roster
WHERE ACCTUSER = \'' . $user_info['username'] . '\'');


-[Unknown]

nil


Elijah Bliss

What if the second forum is located on another server?

[Unknown]

Quote from: Elijah Bliss on September 12, 2004, 04:53:52 PM
What if the second forum is located on another server?

Then it's nearly impossible... or you could just use one MySQL server still, but it would be horridly slow.

-[Unknown]

Spaceman-Spiff

I didn't realize some queries use single quotes instead of double...

Quote from: Elijah Bliss on September 12, 2004, 04:53:52 PM
What if the second forum is located on another server?
Usually webhosts don't allow remote database access. But if you own the server yourself, you can try to configure it to allow remote access.

[Unknown]

Quote from: [Unknown] on September 12, 2004, 01:22:19 AM
$qrycr = mysql_query('
SELECT membergroup, ACCTUSER
FROM smf_roster
WHERE ACCTUSER = \'' . $user_info['username'] . '\'');


Quote from: Spaceman-Spiff on September 21, 2004, 01:48:17 AM
I didn't realize some queries use single quotes instead of double...

None do currently in the SMF code base, that query is not from SMF.

-[Unknown]

Nic

Firstly, thanks SO much for this post - it was exactly what I needed.  I now have two forums for two sub-domains on the same site using one member table, which is just what I wanted.  however, I did notice one thing (no biggy, but wondered if I could fix it).  If someone registers on one forum, the member count automatically adds another one on, but on the other forum it doesn't and I have to tell it to recount the totals.  it's not a big hassle at the moment, since both forums are just new and not many people are registering, but if the forums get bigger it could be annoying having to recount totals each time a new member joins.  Is there any way around this?


Nic

Hi, Anguz.  That's more or less what I have done with my board, but it still won't tally the members on the second board if they register on the first, or vice versa...

[Unknown]

Find, Sources/Subs.php:

updateSettings(array(
'latestMember' => $latestmember,
'latestRealName' => $latestRealName,
'memberCount' => $memberCount,
'unapprovedMembers' => $unapprovedCount
));


Replace:
db_query("
REPLACE INTO prefix1_settings
VALUES ('latestMember', '$latestmember'),
('latestRealName', '$latestRealName'),
('memberCount', '$memberCount'),
('unapprovedMembers', '$unapprovedCount')", __FILE__, __LINE__);

db_query("
REPLACE INTO prefix2_settings
VALUES ('latestMember', '$latestmember'),
('latestRealName', '$latestRealName'),
('memberCount', '$memberCount'),
('unapprovedMembers', '$unapprovedCount')", __FILE__, __LINE__);


-[Unknown]

Anguz

Quote from: Nic on October 31, 2004, 05:17:25 AM
Hi, Anguz. That's more or less what I have done with my board, but it still won't tally the members on the second board if they register on the first, or vice versa...

That'd be because that information is saved in the settings table.
Cristián Lávaque http://cristianlavaque.com

Nic

Thanks both of you.  Just what I needed [Unknown].  I had looked at that bit before but couldn't for the life of me figure out what to change it to.  It's now working perfectly :)

Anguz

Heh, I didn't see [Unknown]'s reply when I posted mine last night. We did it at the same time.
Cristián Lávaque http://cristianlavaque.com

jamesgrant

hello....


I've just added another forum to my hosting - but i already have a well established forum running.... but i wanted to create another forum that another website is going to use later on in the year, it all works fine, and i changed the themes database entries too just like [unknown] suggested... but i've hit a bit of a problem:

Now on the new forum, it all connects fine, but i have a cross between the original SMF template, and the template i was using... and if i try to access anything to do with the theme's settings in admin, i get this:

Unable to load the 'Settings' template.

Can you help??? my new forum looks like a mutant of my first forum!!!!  :'( :'( :'( :'( :'(

The original forum is here: http://www.cardiffscene.com/v6/index.php
and the new forum using my first forum's accounts is here: http://www.cardiffscene.com/mardigras/community/index.php

how can i fix it lol

[Unknown]


jamesgrant

ok... looking at again closer, ummm i dunno what's i've managed to do lol

I've noticed that the new forum doesnt have the users listed in it..... so maybe it's not working correctly.
I get all of my personal messages from the original forum when i log into the new forum though!

and if i click on the 'more stats', i get "unable to load the stats template"


what have i done??!!!!!  :-\ :'( :'(

James

jamesgrant

yeh it looks fine, but none of my members are there.... yet i can get my personal messages...

It's only when you log in that it explodes lol....

do i need to copy any of my themes' files from my original forum into the new forums' directory???? i didnt think i'd have to as i'd updated the 'themes' bit of the .php files like you suggested


>:( >:( >:( lol

Advertisement: