Advertisement:

Author Topic: Share user database for 2 (or more) different forums.  (Read 361681 times)

Offline Spaceman-Spiff

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,524
  • Gender: Male
Share user database for 2 (or more) different forums.
« on: September 03, 2004, 09:14:44 PM »
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... ::)
« Last Edit: May 08, 2008, 03:03:15 PM by Spaceman-Spiff »

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Share user database for 2 (or more) different forums.
« Reply #1 on: September 03, 2004, 09:50:40 PM »
I'd share the themes table too.

-[Unknown]

Offline nil

  • Sr. Member
  • ****
  • Posts: 969
  • Gender: Male
  • Psalm 139
    • Angorn
Re: Share user database for 2 (or more) different forums.
« Reply #2 on: September 12, 2004, 12:48:39 AM »
What if its in the format: ' . $db_prefix . '

Such as how do I change this line to point at smf_roster?
Code: [Select]
$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!

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Share user database for 2 (or more) different forums.
« Reply #3 on: September 12, 2004, 01:22:19 AM »
Find:

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

Replace:

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

-[Unknown]

Offline nil

  • Sr. Member
  • ****
  • Posts: 969
  • Gender: Male
  • Psalm 139
    • Angorn
Re: Share user database for 2 (or more) different forums.
« Reply #4 on: September 12, 2004, 01:25:18 AM »
thanks!

Offline Elijah Bliss

  • Sophist Member
  • *****
  • Posts: 1,340
Re: Share user database for 2 (or more) different forums.
« Reply #5 on: September 12, 2004, 04:53:52 PM »
What if the second forum is located on another server?

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Share user database for 2 (or more) different forums.
« Reply #6 on: September 12, 2004, 05:35:10 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]

Offline Spaceman-Spiff

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,524
  • Gender: Male
Re: Share user database for 2 (or more) different forums.
« Reply #7 on: September 21, 2004, 01:48:17 AM »
I didn't realize some queries use single quotes instead of double...

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.

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Share user database for 2 (or more) different forums.
« Reply #8 on: September 21, 2004, 02:03:00 AM »
Code: [Select]
$qrycr = mysql_query('
SELECT membergroup, ACCTUSER
FROM smf_roster
WHERE ACCTUSER = \'' . $user_info['username'] . '\'');

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]

Offline Nic

  • Semi-Newbie
  • *
  • Posts: 32
Re: Share user database for 2 (or more) different forums.
« Reply #9 on: October 26, 2004, 11:41:05 AM »
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?

Offline Anguz

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,430
  • Gender: Male
    • cristianlavaque.com
Cristián Lávaque http://cristianlavaque.com

Offline Nic

  • Semi-Newbie
  • *
  • Posts: 32
Re: Share user database for 2 (or more) different forums.
« Reply #11 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...

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Share user database for 2 (or more) different forums.
« Reply #12 on: October 31, 2004, 05:41:46 AM »
Find, Sources/Subs.php:

Code: [Select]
updateSettings(array(
'latestMember' => $latestmember,
'latestRealName' => $latestRealName,
'memberCount' => $memberCount,
'unapprovedMembers' => $unapprovedCount
));

Replace:
Code: [Select]
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]

Offline Anguz

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,430
  • Gender: Male
    • cristianlavaque.com
Re: Share user database for 2 (or more) different forums.
« Reply #13 on: October 31, 2004, 05:44:22 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

Offline Nic

  • Semi-Newbie
  • *
  • Posts: 32
Re: Share user database for 2 (or more) different forums.
« Reply #14 on: October 31, 2004, 06:28:46 AM »
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 :)

Offline Anguz

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,430
  • Gender: Male
    • cristianlavaque.com
Re: Share user database for 2 (or more) different forums.
« Reply #15 on: October 31, 2004, 02:00:11 PM »
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

  • Guest
Re: Share user database for 2 (or more) different forums.
« Reply #16 on: November 02, 2004, 04:26:10 PM »
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

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Share user database for 2 (or more) different forums.
« Reply #17 on: November 02, 2004, 04:30:04 PM »
Looks okay to me?

-[Unknown]

jamesgrant

  • Guest
Re: Share user database for 2 (or more) different forums.
« Reply #18 on: November 02, 2004, 04:30:53 PM »
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

  • Guest
Re: Share user database for 2 (or more) different forums.
« Reply #19 on: November 02, 2004, 04:32:44 PM »
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