0

Can a server(example2.com) set a cookie to a client(example1.com) with domain as 'example1.com' when an api call is made from example1.com to example2.com

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197

1 Answers1

0

I don't think it is possible to set cookies from one domain to another because if this happens there will be a lot of flaw in security.

You need to get example2.com to set the cookie. If example1.com redirect the user to example2.com/setcookie.php?example3=value

The setcookie script could contain the following to set the cookie and redirect to the correct page on example2.com

<?php
    setcookie('example1', $_GET['example3']);
    header("Location: example2.com/landingpage.php");
?>

For more visit:

https://stackoverflow.com/questions/6761415/how-to-set-a-cookie-for-another-domain#:~:text=Setting%20cookies%20for%20another%20domain,encode%20this%20into%20the%20url.&text=You%20can't%2C%20at%20least,be%20a%20nasty%20security%20risk.

There is good discussion on similar topic.

Prabesh Gouli
  • 413
  • 3
  • 11