3

Is it possible to set cookie in one domain and access the same in another domain?

Actually I need to set a cookie in A.com page when user clicks a button and then user needs to be redirected to B.com. But the cookies are working for the same domain but not for other domain.

halfer
  • 19,824
  • 17
  • 99
  • 186
user241674
  • 31
  • 1
  • 2
  • 1
    http://stackoverflow.com/questions/3342140/cross-domain-cookies maybe you find answer here – Konstantin Zadiran Dec 02 '15 at 14:54
  • Possible duplicate of [How to set a cookie for another domain](http://stackoverflow.com/questions/6761415/how-to-set-a-cookie-for-another-domain) – CoderPi Dec 02 '15 at 14:55
  • You can set a cookie in `A.com` and redirect to a script on `B.com` that will set a cookie for you. This approach generally uses hashing techniques so that B can tell that the request has come from an authorised source. – halfer Jan 03 '16 at 21:43

3 Answers3

3

Is it possible to set cookie in one domain and access the same in another domain?

No. That would be a security risk.

Cookies were designed for maintaining state, like user preferences. Would you like Joe Random Evil Site to be able to change your preferences for your Online Banking service?

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
3

No. You can only set cookies for the domain your script is currently running on.

CoderPi
  • 12,985
  • 4
  • 34
  • 62
0

if you have both A.com and B.com, you can simply make a http (or https whatever) request from A to B and put on it whatever you want to pass to B.com . B.com gets the request, saves it serverside, when user enters the B.com, server sends back the data to user.

arikanmstf
  • 462
  • 7
  • 16