We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42223
    • 7 Posts
    Hi all,

    I have built a site in Revo 2.2.4 which includes 4 contexts, each on a separate domain name.

    One domain can be thought of as the main domain, then there are three sites displaying products, each from a different brand.

    I'm trying to find a way to have a shopping basket that can persist across all 4 contexts. I have looked online and realise that sessions are domain specific, but I'm hoping there is a way to achieve something similar using the ModX contexts. I see in the database ModX seems to be saving the session information, which leads me to think (or more accurately hope) that it is possible to do this.

    It is not possible to move to a single domain, or to move to subdomains, the products HAVE to remain on their own individual domains.

    I've tried changing the session_cookie_domain setting for all contexts to the main domain, I've tried putting an iFrame on the brand websites to initiate a session on the main domain, but none of this seems to work, and I'm running out of ideas.

    Has anyone done something similar in ModX, or have any suggestions?

    Thanks in advance
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You are dealing with separate domains, so you will have to deal with the situation as if it were in fact separate websites. Sessions are usually cookie-driven, with the cookie holding the session ID. Cookies can only be used by the domain that issued them, so sessions cannot be shared between domains without some way of passing the session ID in another way.

      http://www.gonnalearn.com/2008/04/10/sharing-session-data-across-domains-with-php/
      http://stackoverflow.com/questions/3790179/php-passing-session-data-between-different-domain-names

        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 40045
        • 534 Posts
        I have never had a scenario like yours, but what I would try in your situation was not using cookies/sessions for the shopping cart =)...try to use HTML5 local storage (with some js addons for IE) and save the cart information there...would be interested if you try that, how you implement it and if it works =)...just if such a scenario should show up on my horizon in the future^^

        EDIT: Thanks Susan for the article above, didn't know (or never tried) that localStorage is also domain / subdomain specific! And also having learned from that "old" article that there are possibilities to go around this is very nice to know... [ed. note: exside last edited this post 13 years, 10 months ago.]
          • 28042 ☆ A M B ☆
          • 24,524 Posts
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 42223
            • 7 Posts
            Hi guys,

            Thanks very much for all the suggestions. I'm leaning more towards the X-Auth solution that uses local storage as that avoids the need to be passing POST variables whenever you lonk between the websites. The UX for browsing the site is such that you can move between all 4 domains quite freely, sometimes without even noticing, and the use of POST variables sounds a bit impractical in my situation.

            Has anyone used X-Auth with local storage before? Is it cross browser compatable (work with IE7+) and how long does the data last for? I'm guessing since it is local storage it would last for as long as the browser was open?
              • 42223
              • 7 Posts
              Sorry, just realised that article posted by sottwell has a list of browsers Auth-X can work with: Internet Explorer 8+, Firefox 3.5+, Safari 4+, Chrome 4+, and Opera 10.5+

              I guess this is ok. I still aim to have sites working well in IE7, but I guess this will be a small compromise to get this working.

              I'm still keen to hear from anyone who has successfully used Auth-X to share data across multiple domains, and is they are pleased with the end result.
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                I believe that actually Auth-X is just used as an example of cross-domain data sharing. The trick is using the new HTML5 local storage, and using iframes to trick the browser into allowing access to storage belonging to different domains.

                Originally the HTML5 local storage specification had a feature to allow cross-domain access, but it was removed out of security concerns.

                You could also use AJAX and some temporary database or file system storage for this; it might be a good use for sqlite with AJAX.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 22303 MODX Staff
                  • 10,725 Posts
                  You could use the modRegistry API to store/retrieve the data server-side without any dependence on SESSIONs or other domain-restrictive storage mechanism.
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 42223
                      • 7 Posts
                      Ah ha, that modRegistry API seems to potentially solve my problem. Thank you Jason, and thanks as well sottwell, the example in the link you sent is helping me understand how it might work.

                      It looks like I can create a "register" called e.g. "basket", then subscribe the user to that registry, which will allow them to write/read information to a file (or database, although in my case I think file would be best). The user can then add/remove products from any of the domain names (contexts) into the "basket" registry.

                      I assume when the user "subscribes" to the basket registry, this will create a unique basket instance for that user, i.e. the basket information will be available only to that single user, but across all domain names?