We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22303 MODX Staff
    • 10,725 Posts
    Quote from: johnpottinger at Dec 03, 2012, 10:48 AM
    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?
    You just need to create a unique topic name which you can subscribe to in order to send/retrieve the specific message or messages in that topic. You would likely want to create a topic based on their user id, user name or some other unique identifier.
      • 42223
      • 7 Posts
      Oh right, so what could I use as a unique identifier so I can mimic a session using the modRegistry tool? I can't use just the IP address as this could be shared across multiple computers on a local network, so is there another unique number or string I can use instead?
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Use the user's email address, or a combination of his username, email and user ID. Something unique to the user.
          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
          The user doesn't log in, they just browse through the websites adding products to their basket, so if I were to use this method I need to find a unique identifier that isn't the user personal details. Can this be done, or should I go back to looking at the localStorage option?
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            IP address along with a time range? i.e. IP address + timestamp, and if the timestamp part is within the last 20 minutes or so it's used for the identifier? Establish a unique string and pass it in the URL or with a hidden field; it would be much less of a security problem than using the session ID in the same way, since even if somebody does sniff the URL it won't give them anything sensitive.
              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
              But if the unique identifier is a timestamp, would I then have to continually rename the topic with new timestamps, otherwise after 20 minutes the data will no longer be available, regardless of whether the user has actively been on the site or not? I understand only having data available for 20 minutes of inactivity, but it strikes me there would be a lot of work involved in getting this to work like a session where the data remains for as long as the user is active.

              I'm erring more towards the localStorage option again, as it seems I can have a page on the main domain to act as the "data server". I'm thinking to have a page on the main domain with a whitelist of all the domains in question, then whenever someone visits a page n any of the sites it includes an iFrame that visits the "data server" page and retrieves info. This sounds like similar to one of my attempts to get sessions to work across domains, but using localStorage instead.

              I just hope I can ping AJAX requests to the data server page too, so I can update the basket as the user adds/removes items from the basket.

              I will update this page to let you know if this works, for anyone else with a similar problem...