Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Aaron10 on December 22, 2012, 11:52:06 AM

Title: Same SMF Forum on multiple sites/domains
Post by: Aaron10 on December 22, 2012, 11:52:06 AM
Hi guys, need some help doing this. I want an SMF forum on multiple sites/domains, for example:

site1.com/forum
site2.com/forum
site3.com/forum

Would be 3 different sites but each sharing the same forum. I have sort of achieved this by using this in the settings.php file:

//$boardurl = 'http://mydomain.com/forum'; # URL to your forum's folder. (without the trailing /!)
$siteurl_1 = 'mydomain.com';
$siteurl_2 = 'myotherdomain.com';

$boardurl = 'http://' . ($_SERVER['HTTP_HOST'] == $siteurl_2 ||  $_SERVER['HTTP_HOST'] == 'www.'.$siteurl_2 ? $siteurl_2 : $siteurl_1 ) . '/forum'; # URL to your forum's folder. (without the trailing /!)


From Here (http://www.simplemachines.org/community/index.php?topic=125902.msg804509#msg804509)

This does work but I can't login on any of the forums with any accounts. Also, would I be able to have a separate themes folder for each domain rather than them all sharing the same one? I'd like each one to have a different banner and background color, other than that they'll all use the same theme, footer etc.

Thanks in advance.
Title: Re: Same SMF Forum on multiple sites/domains
Post by: emanuele on December 22, 2012, 12:13:35 PM
Quote from: Aaron10 on December 22, 2012, 11:52:06 AM
This does work but I can't login on any of the forums with any accounts.
Did you apply the changes to Subs-Auth.php?

Quote from: Aaron10 on December 22, 2012, 11:52:06 AM
Also, would I be able to have a separate themes folder for each domain rather than them all sharing the same one? I'd like each one to have a different banner and background color, other than that they'll all use the same theme, footer etc.
That looks like this:
http://www.simplemachines.org/community/index.php?topic=491395.0
Unfortunately still not 100% fixed...
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Aaron10 on December 22, 2012, 11:02:42 PM
Quote from: emanuele on December 22, 2012, 12:13:35 PMDid you apply the changes to Subs-Auth.php?

There isn't any difference in my subs-auth to this:

// Any alias URLs?  This is mainly for use with frames, etc.
if (!empty($modSettings['forum_alias_urls']))
{
$aliases = explode(',', $modSettings['forum_alias_urls']);

$temp = $boardurl;
foreach ($aliases as $alias)
{
// Fake the $boardurl so we can set a different cookie.
$alias = strtr(trim($alias), array('http://' => '', 'https://' => ''));
$boardurl = 'http://' . $alias;

$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));

if ($cookie_url[0] == '')
$cookie_url[0] = strtok($alias, '/');

setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0], 0);
}

$boardurl = $temp;
}


Unless I'm supposed to put in the right URLs, when I try to login on site2.com it redirects me to site1.com

Quote from: Aaron10 on December 22, 2012, 11:52:06 AMThat looks like this:
http://www.simplemachines.org/community/index.php?topic=491395.0
Unfortunately still not 100% fixed...

I may have to resort to bringing my header forward through an iframe which would get the job done until it is ever fixed.

EDIT: Actually just simply using

$boardurl = 'http://'.$_SERVER['HTTP_HOST'].'/forum';

Seems to work fine without any login problems/redirects. Gonna keep this topic open though while I test it and if I need any help with the themes.
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Aaron10 on December 23, 2012, 11:41:26 PM
Ok managed to modify the header by using local links to images and recreating the directory on my other sites. All images and links are working fine, except the back ground color needs changing. How/where do I attach my own CSS stylesheet so it can use the the background color from there? I thought it would be index.template.php but it didn't work (I did remove the background color style from my theme' CSS as well as the normal links, so there are no duplicate styles between the two stylesheets).

Also about the cookies across multiple domains - all my domains are addon domains, so they all basically share the same IP:

12.345.678.90/domain1/forum.php
12.345.678.90/domain2/forum.php
12.345.678.90/domain3/forum.php

etc.

So would there be no way to have the cookies look at those URLs or not?
Title: Re: Same SMF Forum on multiple sites/domains
Post by: emanuele on December 24, 2012, 06:14:17 AM
Add to your settings table (in the database) a new record:
forum_alias_urls
and value for it a comma separated list of your domains:
domain1.com,domain2.com,domain3.com
that should work with the code in Subs-Auth.php above (sorry, I misread SleePy's post, he intended that this is an "hidden" feature of SMF and just setting the proper value into the database it will work).
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Aaron10 on December 24, 2012, 08:09:52 AM
Am I also supposed to do something in modsettings? I added that to the database and have in my subs-Auth:

// Any alias URLs?  This is mainly for use with frames, etc.
if (!empty($modSettings['forum_alias_urls']))
{
$aliases = explode(',', $modSettings['forum_alias_urls']);

$temp = $boardurl;
foreach ($aliases as $alias)
{
// Fake the $boardurl so we can set a different cookie.
$alias = strtr(trim($alias), array('http://' => '', 'https://' => ''));
$boardurl = 'http://' . $alias;

$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));

if ($cookie_url[0] == '')
$cookie_url[0] = strtok($alias, '/');

setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0], 0);
}

$boardurl = $temp;
}


But they're still not sharing the cookies.

I solved the background color issue anyway by just using a 1 pixel color repeated.
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Kindred on December 24, 2012, 09:37:23 AM
as far as I know, you can not actually share cookies across multiple domains.
sub-domains, YES... actual domains, no.

My company did this for their forum sites back when RC3 was out... and got everything running properly except the cookies.  If you would be interested in releasing it as an official, free, modification (BSD licensed), I will send you the code they used - you can modify it as needed to work on 2.0.3 and package it as a mod...
Title: Re: Same SMF Forum on multiple sites/domains
Post by: emanuele on December 24, 2012, 12:02:15 PM
The code above (taken from Subs-Auth.php) should set the cookies for any domain listed in the "hidden" setting "forum_alias_urls".

Sorry, never used that funzion, without putting my hands on it I can't tell you much more...
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Aaron10 on December 24, 2012, 07:14:32 PM
Quote from: Kindred on December 24, 2012, 09:37:23 AM
as far as I know, you can not actually share cookies across multiple domains.
sub-domains, YES... actual domains, no.

But what if the forums are all under the same IP address (since they're all addon domain names in my case)?
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Kindred on December 24, 2012, 08:10:54 PM
That doesn't matter...   cookies are identified by domain, regardless of the IP
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Aaron10 on December 24, 2012, 11:36:25 PM
Well that's a bummer.

Do you know if that code you spoke of works with 1.1.X?
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Kindred on December 25, 2012, 12:24:33 AM
No, the code we worked on was done for 2.0 rc3
It should be fairly easy to port up to 2.0.3, but back porting to 1.1.x would be much more difficult
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Hj Ahmad Rasyid Hj Ismail on December 26, 2012, 12:14:38 AM
If you are using SMF 2.0 I would suggest you to try Portamx Subforum Mod (http://portamx.com/) instead.  ;)
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Kindred on December 26, 2012, 07:20:26 AM
aharis, that will not work across domains... only across subdomains
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Hj Ahmad Rasyid Hj Ismail on December 26, 2012, 07:30:17 AM
I am using the mod and use it successfully on both domain and subdomain. :P But that doesn't matter, he wants it for 1.1 branch which is not supported by the said mod.
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Aaron10 on December 28, 2012, 11:31:45 PM
Yeah I'll just leave it as is. I have another question though, how would I setup separate meta description since they all share the same index.template.php? Can a separate file be attached or can it be done in settings or root index.php?
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Hj Ahmad Rasyid Hj Ismail on December 29, 2012, 01:22:15 AM
Basically, I do not know what you have done at this stage so to give further idea as to that is quite impossible.

You can look further here: http://custom.simplemachines.org/mods/index.php?action=search;basic_search=meta
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Arantor on December 30, 2012, 02:33:09 PM
And if they're the same content, you'll get penalised by search engines to boot.
Title: Re: Same SMF Forum on multiple sites/domains
Post by: Hj Ahmad Rasyid Hj Ismail on December 30, 2012, 10:12:39 PM
Exactly.