Transferring cookies to subdomain located in different Server using PHP

22 Views Asked by At

How can we pass on cookies to the subdomain if it's on a different server?

Basically, the main domain is on siteground while the subdomain is on softr.io.

I'm using it for the authentication, so when someone logged in to main domain, he/she can access the login session on subdomain as well.

The softr.io haven't ability to add PHP code so I'm left with only using Javascript on the subdomain.

I used the following cookie code:

setcookie($cookie_name, $cookie_value, $expiration_time, '/', $subdomain, true, true);

It shows the cookie in the Application tab of developer tools but is unable to access in JavaScript by document.cookie.

Is anyone here who has already tried this type of task and can guide me.

I did research for a few hours but was unable to figure it out.

1

There are 1 best solutions below

0
Quentin On

The 7th argument to setcookie is the HTTP Only flag.

You’ve set it to true which explicitly prevents it from appearing in document.cookie.

Turn that security feature off if you want to read it with client-side JS.