Before I say a word, if this topic exists elsewhere feel free to call me an idiot for not finding it and point me towards it. I looked, but didn't find anything.
Would it be possible to share session data across multiple domains, when all the domains are hosted off one account? I've got a client who has one hosting account with 2 addon domains, so all the files are within their section of the server (which means, as far as I understand it, they all use the same temp folder for php sessions). I know that PHP can only access sessions for the domain its running from, but would there be any way to get this working? Basically the client has 2 different online stores which sell similar items, and one main site to do the checkout (they want two separate sites for ordering, but then the items can be shipped together when they complete their order). I've set up single site e-commerce easily enough, but this one is really getting to me.
So, when the user logs into their account on the main site, could I create 2 additional sessions for the other 2 sites? Or, simpler, could these sites read the session since it's within the same folder?
I really appreciate any insight!
Shared Sessions On One Account
Moderator: General Moderators
Re: Shared Sessions On One Account
Accessing the session data is not a problem. I would recommend you to use a database instead of the default session handling, but anyway you can load the data from file as well, if you have access to the file.
The problem is with the session id, as the browser won't send a cookie that belongs to one domain to another domain. The solution for this is to have iframe/img/whatever else on both domains, that points to one and the same location and is used to access the data.
Then you need a second identifier, you will use it when you call a script to get the data for that user.
So basically, if you have domain1 and domain2, and a script to track session data at domain3 (it can be domain1 or domain2 as well, but I'm calling it domain3 just because of separation)
* Customer goes to domain1. Domain1 starts a session with id s1 and loads image/iframe from domain3, passing id=s1
* Domain3 creates a session, issuing new session id, and saves to its database/file s1=session_id()
* Customer goes to domain2. Domain2 start a session with id s2 and loads domain3?id=s2. Domain3 however receives the cookie from the user and maps s2 to the same session, as s1
Domain1 and Domain2 use some technique to ask domain3 for the session data. This can be database/file read as they are really on one server, it can be javascript or something else.
Hope all of this make sense. If you have any further questions, I will be glad to help you.
The problem is with the session id, as the browser won't send a cookie that belongs to one domain to another domain. The solution for this is to have iframe/img/whatever else on both domains, that points to one and the same location and is used to access the data.
Then you need a second identifier, you will use it when you call a script to get the data for that user.
So basically, if you have domain1 and domain2, and a script to track session data at domain3 (it can be domain1 or domain2 as well, but I'm calling it domain3 just because of separation)
* Customer goes to domain1. Domain1 starts a session with id s1 and loads image/iframe from domain3, passing id=s1
* Domain3 creates a session, issuing new session id, and saves to its database/file s1=session_id()
* Customer goes to domain2. Domain2 start a session with id s2 and loads domain3?id=s2. Domain3 however receives the cookie from the user and maps s2 to the same session, as s1
Domain1 and Domain2 use some technique to ask domain3 for the session data. This can be database/file read as they are really on one server, it can be javascript or something else.
Hope all of this make sense. If you have any further questions, I will be glad to help you.