Jump to content

Using multi-site support built into PW's core


Adones
 Share

Recommended Posts

I would like to use ProcessWire for several websites.

Each website has its own customized template.

Each website makes extensive use of forms so that users can search for goods and services. 

Members of the site can add their own goods and services and they can be contacted by other members of the site.

All websites will be accessible under the same domain (www.maindomain.com, www.maindomain.com/website2, www.maindomain.com/website3 and so on)

Domain mapping will be used so that the own domain of the website is displayed. The own domain of the website is the name of the website.

Users should not have to register on each website. Once the user has registered on one website, the member shall be logged in on all websites under the same username and password. Obviously, all websites need to share one and the same database.

Multiple websites at independent domains and subdomains from the same ProcessWire installation and web hosting account using the same database can be realized by installing the 3rd party module "Multisite module". This 3rd party module, however, means additional work through upgrades etc. and the ProcessWire API usage must be coded in recognition of the multi-site environment. Therefore this method is no option for me.

Luckily, multi-site support is built into ProcessWire's core and thus doesn't require installation of any module. Multiple sites are running on the same web account and ProcessWire installation. I want to make use of this method.

But as each site is maintaining its own database (and /site/ directory), I need a solution so that when a user is registered and logged in on one website, the user is automatically logged in on all websites.

The websites shall also be connected with a forum software (xenForo) and with a shopping cart (one that is similar to the architecture of PW). Both will be hosted in the same web account where PW is hosted.

User registration shall be on the main website accessible under the main domain (www.maindomain.com/register).

The user is free to log in on the website of his choice or in the forum or in the shop.

After logging in, the user would be logged in throughout the whole web property (websites, forum, shop).

As the database of the main website under the main domain (www.maindomain.com is displayed) contains the data for user registration, I may need a bridge to connect the login field on all other websites and forum and shop with that main database.

In that main database not only the simple user registration data is stored, but also other essential member data that is required by the forum software, by the shopping cart, by some websites.

All websites, the forum and the store are bridged with that main database so that they can make use of those additional data.

I'm sure that I am not the only one who prefers the multi-site support built into PW's core and therefore many PW admins would want such a solution.

Link to comment
Share on other sites

Welcome to the forums, Adones!


I need a solution so that when a user is registered and logged in on one website, the user is automatically logged in on all websites. 
I did some research and crossdomain user accounts are not really easy/straightforward. I'm not even sure if this is a ProcessWire thing, If you make any progress on that area I would be glad to know!
Link to comment
Share on other sites

Thank you for welcoming me. I like the friendly atmosphere here in the PW forum.

Please keep in mind that everything is stored in the same web hosting account and that all websites and the forum and the shop is accessible under one and the same domain (www.maindomain.com , www.maindomain.com/website2 , www.maindomain.com/website3 , www.maindomain.com/forum , www.maindomain.com/shop ). The fact that for all websites except the main website domain mapping is used, shouldn't create any problems when bridging the database of each website, of the forum and of the shop with the main website.

If someone can offer such a bridge, then it can only be for a CMF like ProcessWire. 

Otherwise PW's multi-site support cannot be used.

In that case, on a single installation of PW all websites would run. This is possible because each page starts blank and would be developed like a new website.

Then this singe PW database would have to be bridged with the forum software and the shopping cart. All three software are in the same web hosting account.

This is the method used at the open-source CMS/CMF Pimcore. But Pimcore works with ExtJS and not with JQuery. Therefore Pimcore is very heavy and ProcessWire is light-weight. I really like to accomplish my web endeavor with ProcessWire. I hope you guys don't give up before even starting it.

Link to comment
Share on other sites

I didn't read your post carefully, my apologies. When a user succesfully logs in you could store a cookie with the path "/" (so other sites can read it) with the user ID. When on another site you can check if that particular cookie is set and automatically log them in. This is not really secure since fetching a cookie with an user ID is fairly simple. You might want to add some layers of security. Perhaps someone else would know how to correctly deal with this. 

Link to comment
Share on other sites

Assuming the other domains are completely different (and not just subdomains) it is a little tricky to have the user logged in all of them, unless you are using some external service to manage the logins (whether one you've written or an already existing service). For instance, consider that Facebook recognizes you as logged in as you browse through other websites.

But if you are looking for a simple solution, one possible is to use Javascript to duplicate the login form POST submission to other sites.  I don't know of a way to do it without Javascript just because the client side (user) is the one that must actually login, so Javascript being client side, lets you perform that action for them without them knowing it. 

This is just untested pseudocode, but hopefully it gets the idea across.

<form id='login-form' method='post' action='/login/'>
  <label><input type='text' id='user' name='user'> Username</label>
  <label><input type='password' id='pass' name='pass'> Password</label>
  <input type='submit'>
</form>

<?php if($config->httpHost == 'maindomain.com'): ?>
<script>
  $(document).ready(function() {
    $("#login-form").submit(function() {
      var data = {
        'user': $("#user").val(),
        'pass': $("#pass").val(),
        'submit': 'submit'
        };
      $.post('https://www.otherdomain.com/login/', data); 
      $.post('https://www.adones-site.com/login/', data); 
    }); 
  });
</script>
<?php endif; ?> 

Now I'm not positive it would work exactly like this. You might have to open an invisible iframe to each of those external sites first to establish a session, but that would be fairly simple, just by adding some hidden <iframe> tags to the login forms  of those other sites after your <form>. There may be other factors too, but I think this would work. 

Your /login/ page would also need something to detect when it is being submitted to, and login the user in:

<?php 
if($input->post->user && $input->post->pass) {
  $name = $sanitizer->pageName($input->post->user);
  $user = $session->login($name, $pass));
  if($user->id) {
    // login success
    if($config->httpHost == 'maindomain.com') $session->redirect('/wherever/you/want/');
      else echo "Success"; // presumably this will never be seen
  } else {
    // login failed
    if($config->httpHost == 'maindomain.com') $session->redirect('/login/'); 
       else echo "Failure"; // presumably this will never be seen
  }
}
  • Like 2
Link to comment
Share on other sites

Thanks, Ryan, simple solutions are always great. 

I have come to the conclusion that for my web endeavor, I actually don't need the PW multi-site support.

That's because PW allows me to regard a tree of pages as a website and I can make use of access control templates.

For each tree, I would apply domain mapping. Is that possible with PW 2.4?

Each tree would get an own blog module.

Each tree (=website) has an own search module. I would have to limit the search feature to that tree of pages. Is there a search module where I can set restrictions for the search? I would install a search module for each tree. Let me call it 'tree-search'.

Like a blog module and a search module for each tree, I also like to install a forum module and a shop for each tree. Is there anything like that?

To my mind, this is the only elegant solution to host multiple websites on PW having just one database and thereby enabling the users to register and login only once and not on each website.

It would be great if the 'tree-forum' and the 'tree-shop' would be open-source and similar to the architecture of PW.

Then an own developer community for the tree-shop and for the tree-forum would be created.

And Processwire.com would no longer need to use InvisionPower-Board anymore.

I believe that with an architecture similar to that of PW, an open-source tree-forum and an open-source tree-shop could easily compete with my favorite forum software xenForo and with any established open-source shopping cart.

Link to comment
Share on other sites

For each tree, I would apply domain mapping. Is that possible with PW 2.4?

That's essentially what the multi-language support solutions are doing. PW 2.4 doesn't change or add anything in this regard. 

Each tree (=website) has an own search module. I would have to limit the search feature to that tree of pages. Is there a search module where I can set restrictions for the search? I would install a search module for each tree. Let me call it 'tree-search'.

Careful with use of the term "module" in this context, just because that means something different in ProcessWire (a plugin). And things like blog and search are not modules in ProcessWire, but things that you build with pages. However, you can restrict a search to any branch in the tree just by calling find() on the page that represents that branch, rather than $pages. For example:

$pages->find("your selector"); // searches entire site
$pages->get('/products/2013/')->find("your selector"); // searches everything below /products/2013/
$pages->get('/products/2013/')->children("your selector"); // searches only immediate children of /products/2013/
Like a blog module and a search module for each tree, I also like to install a forum module and a shop for each tree. Is there anything like that?

There are forum and shop modules (by @apeisa). But these are both labeled as "proof of concept" modules, meaning they are not necessary turn-key solutions so much as solutions for you to examine, learn from, build from, adapt to your needs. I also don't think that these modules are deigned for multiple-installations on the same site, but not positive. 

To my mind, this is the only elegant solution to host multiple websites on PW having just one database and thereby enabling the users to register and login only once and not on each website.

I'm not sure you need to let the needs of user accounts dictate the approach. I personally would be more inclined to isolate the user accounts from the sites for this particular need, perhaps running a separate PW installation that is dedicated to just managing the user accounts for all the domains. But I'm not really sure what the best route is without giving it more time. 

And Processwire.com would no longer need to use InvisionPower-Board anymore.

There are already forum solutions out there that people have spent years developing and making them the best. IPBoard is one of them. We couldn't duplicate that unless we also spent years doing the same. Regardless of how many forum solutions get built as ProcessWire modules, I don't see us moving away from a dedicated platform like IPBoard for this. 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...