News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Same SMF Forum on multiple sites/domains

Started by Aaron10, December 22, 2012, 11:52:06 AM

Previous topic - Next topic

Aaron10

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

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.

emanuele

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...


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Aaron10

#2
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.

Aaron10

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?

emanuele

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).


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Aaron10

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.

Kindred

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...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

emanuele

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...


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Aaron10

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)?

Kindred

That doesn't matter...   cookies are identified by domain, regardless of the IP
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Aaron10

Well that's a bummer.

Do you know if that code you spoke of works with 1.1.X?

Kindred

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
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Hj Ahmad Rasyid Hj Ismail

If you are using SMF 2.0 I would suggest you to try Portamx Subforum Mod instead.  ;)

Kindred

aharis, that will not work across domains... only across subdomains
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Hj Ahmad Rasyid Hj Ismail

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.

Aaron10

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?

Hj Ahmad Rasyid Hj Ismail

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

Arantor

And if they're the same content, you'll get penalised by search engines to boot.
Holder of controversial views, all of which my own.


Hj Ahmad Rasyid Hj Ismail


Advertisement: