This thread will detail how to have a single login for multiple forums. It makes the following assumptions:
A valid vbulletin license exists for each install
All forums will be on the same server
You already have one forum operational AND that forum uses a BLANK $tableprefix!
One database will contain all the tables
This thread is a follow-up from this discussion over at vbulletin.com. Thanks to Brains for some pointers!
Here are the steps:
Copy your forum directories to a parallel directory (for example copy /www/forums to /www/new_forums)
In /includes/config.php, change $tableprefix (line 91) to a new prefix [for example $tableprefix = 'new_';]
Run the vb install from the new directory (/www/new_forums/install/install.php)
During the install, be sure NOT to empty the tables. If you have any doubt about what this means, stop NOW! If you empty the tables, you will lose all of your existing data from a prior install!
Download the files from these directories to your PC: /new_forums, /new_forums/admincp, /new_forums/archive, /new_forums/includes, /new_forums/modcp, /new_forums/subscriptions
We are now going to make global changes to the files in the folders (and subfolders) above. I used Dreamweaver's "edit-find and replace" function with "find in" set to "Entire Current Local Site". We are basically going to remove the "TABLE_PREFIX" from any code dealing with the user. (Note - if you are comfortable with unix command, you could do these changes from the command line on the server.)
Run the following find and replace operations:
Find [" . TABLE_PREFIX . "user] (find what's inside the brackets). Replace with [?.?user] This should find 562 instances of user, usergroup, userfield, and usertextfield
Find [" . TABLE_PREFIX . "strikes] (find what's inside the brackets). Replace with [?.?strikes] This should find 5 instances of strikes
Find [" . TABLE_PREFIX . "pm] (find what's inside the brackets). Replace with [?.?pm] This should find 61 instances of pm, pmtext, pmtextid, and pmreceipt.
Upload these directories back to the server.
We now need to do a little fine tuning
In /includes/functions.php: on line 1171 remove the table_prefix before $idname.
In /includes/adminfunctions: modify print_choser_row (line 1161)to check for $tableid of user, usergroups
PHP Code:
if ($tableid == "user" OR $tableid == "usergroup") {
$result = $DB_site->query("SELECT title, $tableid FROM "."$tablename$wherecondition ORDER BY title");
} else {
$result = $DB_site->query("SELECT title, $tableid FROM " . TABLE_PREFIX . "$tablename$wherecondition ORDER BY title"); // existing code
}
In /includes/adminfunctions_user.php around line 116 (construct_style_chooser)
PHP Code:
$tableid = $tablename . "id";
if ($tablename == "user" OR $tablename == "usergroupid") {
$result = $DB_site->query("
SELECT title, $tableid FROM "."$tablename WHERE userselect = 1
ORDER BY title
");
} else {
// existing code
$result = $DB_site->query("
SELECT title, $tableid FROM " . TABLE_PREFIX . "$tablename WHERE userselect = 1
ORDER BY title
");
}
Done! Both forums are now accessed by the same user table! PM's are unified across forums as is the user count.
Show Your Support
This modification may not be copied, reproduced or published elsewhere without author's permission.
What about Subscriptions are those per user or per board?
Subscriptions to forums and threads would be by board. However, settings like always getting an email to a thread you start would be by user. The trick is looking at what is in the user table. That determines if the setting is by board or by user. For example, since the custom title is in the user table, it will be the same on both forums. (It cannot be different). Same for the user's signature. Since signature is in the usertextfield table (a shared table) it will be the same for both forums.
Quote:
Originally Posted by boostedsti
Also is that a backup copy you are using or is it really live?
Reason I ask is
Great question! It's live! Each forum has it's own stats table so one can see the threads and posts separately for each table. The user number will be off until the nightly cron runs that updates the user count. Some weird effects here but if you dig through the tables and the code it makes sense.
Quote:
Originally Posted by boostedsti
Either way I'm digging script.
Your sites are pretty sweet too.
What transfers with the character to both forums? All of their setting and profile (including profile pic and avatar)? Some of it? None of it?
Ideally it would seem to me you would have password and email the same while everything was per site.
Anything that is in the user* tables is shared between the sites. So, email, sig, custom title, etc. Avatars are trickier. Since the avatar field is in user, the user will have the same avatar number for each site. However, the avatar table is not shared so ... he could have a different avatar on each site. However, he could really only control what one of them looks like! If the user has a custom avatar, he could actually control what is displayed on each site. I guess ideally the avatar table should also be shared.
The only real use I would have for this is if it totally ran like 2 distinct forums that only shared the core user information (username, password, & email).
The only real use I would have for this is if it totally ran like 2 distinct forums that only shared the core user information (username, password, & email).
That would be very hard to do given the current database layout.
I might be more useful if you actually created a second prefix (TABLE_PREFIX_USERS) and used this, rather than removing the prefix - most people use a prefix for a reason.
I might be more useful if you actually created a second prefix (TABLE_PREFIX_USERS) and used this, rather than removing the prefix - most people use a prefix for a reason.
Yes, absolutely. You may have noticed that in my "find and replace" commands I didn't totally remove TABLE_PREFIX. Instead, where the code reads " . TABLE_PREFIX . ", I replaced that with "." One could easily substitute anything else where the dot is between the quotes. Also, if you need to go back and replace TABLE_PREFIX, you could do a "find-replace" on say ["."user] replace with [". SHARED_TABLE_PREFIX . "user].
# !/bin/bash
# Replace a text inside all files of current dir
# Customize $a and $b variables
# text to search
a='TABLE_PREFIX . "user';
# text to replace
b='USER_PREFIX . TABLE_PREFIX . "user';
for i in `grep -lr $a`
do
echo $i;
mv $i $i~
sed -e "s/$a/$b/g" $i~ > $i
rm $i~
done
Run this script from the forum root 4 times: one for "user" (as above), one for "cp", one for "pm", and one for "custom".
Of course, you still need to manually modify the scripts that use a variable like $table instead of 'user[...]' (and stuff), as stated in first post, adding USER_PREFIX where needed, and insert somewhere your definition (I inserted it in class_core.php, just below the TABLE_PREFIX one).
I also noticed a lack in the first post: if you want to also keep avatar images, you should modify image.php in line 129, adding as usual "USER_PREFIX . " before TABLE_PREFIX.
Handy little script. Note that when you run it you should be logged as the web server user. The file's owner and group will get changed to whoever you run the script as. Also, the files will have the permissions changed to whatever that users umask is set to, which will probably be 644 and okay.