How do you handle data shared across multiple domains?


I’m going to have to use data on more than one domain. That data need to be stored, so sessions are out. I guess cookies are out too, since it’s a security issue to share one cookie across multiple domains.

How would you approach an application that has to deal with this problem?

Regards. :slight_smile:


What type of data are you talking about?

You could easily share a database table between multiple domains for something like user accounts and then have individual domain specific tables as required.

In SQL you can prefix a table select with a database, ie.

FROM site_a.products
JOIN site_b.users ON site_a.products.user_id =

btw i’m assuming you mean multiple domains on the same server, which would give you the best results, however you could also have a shared database server that each domain server connects to.

Nope… That would be and Basically, would share data with In other words, would need to use data provided by to function properly. Nothing crazy about the data in question, just an id string.

A shared cookie would just be perfect, but it’s not safe security-wise, and a bit painful to implement, is it?

im no expert on cookies but you might run into browser issues trying to set 3rd party cookies in browsers with high security settings.

Is there no way to query with information that you have available on If has some shared identifier then you could potentially have a script on which would return the data that you want. You could use file_get_contents() for this with some query string parameters. A bit like a bare bones API I guess.

I think it might be helpful if you explain how you got yourself into this situation!

Does the id key you are talking about change depending on the user? Or is it a site-wide key you just need to update periodically?


You could serialize the shared data within a database that both sites can talk to then have a common token that link this data to a user or function or however you need to link the data.

One other option is to have siteA implement a JSON service and have siteB connect to siteA’s JSON service, get the needed data, and parse it. A JSON service could also be implemented on SiteB so siteA could get data from there. This will effectively pass the data between sites.


@ServerStorm - wouldn’t that have to be a JSONP request because of the Cross Origin Resource problem?

Whoops Cups yes I meant to put JSONP thanks for clearing that up! :slight_smile: Yes a regular JSON request would fail due to the cross origin problem but JSONP will overcome this.


Thanks:) Great ideas, will look into that.

Not sure exactly what you are doing but I have two domains that need to maintain shared data and cURL works perfectly.