0

Is there any way to store a cookie in a users browser when he access my website through another website?

Example:

I have website a.com

User sends a request using http://b.com and I'd like to set a cookie for http://a.com with this request.

Is it possible?

rrr
  • 412
  • 4
  • 10
Adrian Pop
  • 39
  • 7
  • 2
    Possible duplicate of [How to set a cookie for another domain](https://stackoverflow.com/questions/6761415/how-to-set-a-cookie-for-another-domain) – Nico Haase Dec 12 '18 at 10:17
  • *"I have website a.com ... and I'd like to set a cookie for http://a.com"* ... sounds perfectly normal... what exactly do you mean by *"User sends a request using http://b.com"*? Do you want a website you don't control to set the cookie for your site? Or do you simply want to set a cookie, on your own site, holding referral data? – CD001 Dec 12 '18 at 10:36
  • "you want a website you don't control to set the cookie for your site" that's what I want. I've made some research and figured that's quite impossible (the way i saw it) – Adrian Pop Dec 12 '18 at 16:54

2 Answers2

1

What you can do is create a PHP script which sets a cookie but does not output anything. Then you can include this script using for example <img> or <script> tags. As soon as the browser tries to load that URL, it will set the cookies you specify in the header (given the fact third website cookies aren't blocked in the browser).

Then the cookie which is set is accessible by any page on a.com

rrr
  • 412
  • 4
  • 10
0

The easiest: Include a resource img src="//a.com/setCookie.php" width="1" height="1" into the content of //b.com

Yuriy Polezhayev
  • 812
  • 8
  • 12