Skip to content
Advertisement

Can’t set cookie on different domain

This URL has the code below: https://trywifibooster.com/test/setCookiesFromAnotherDomain.html?param=SHOULD-SET-TO-THIS

JavaScript

Which should take in the variables passed in the URL. Then save it to this domain as a cookie go.allthatstrendy.com. It’s done through a PHP script executed by AJAX.

The PHP script:

JavaScript

However, when the Ajax on trywifibooster.com is executed, leading to go.allthatstrendy.com, no cookies are set.

After running the URL above. Go to https://go.allthatstrendy.com/intercart/ and check the cookies. It’s not set!

I’ve even set it up so you can execute a script directly on go.allthatstrendy.com and set the cookie directly there. It works like that.

See: https://go.allthatstrendy.com/intercart/cookies/Test/saveCookies2.php?UTMParamsString=TESTjhghgjghj

However, when I try and set the cookie here https://trywifibooster.com/test/setCookiesFromAnotherDomain.html?param=SHOULD-SET-TO-THIS

It doesn’t set it. There is no cross-origin error or anything. I’ve gone back and forth for over 3 hours and I’m honestly about to scream. It makes no sense. I am an experienced developer. So it makes it even more frustrating!

Advertisement

Answer

XHR doesn’t send or accept cookies unless you explicitly enable credential support:

JavaScript

Note that this will make your request preflighted.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement