search

Home  >  Q&A  >  body text

Transfer cookies to subdomains located on different servers, implemented using PHP

<p>How to pass cookies when the subdomain is on a different server? <br /><br />Basically, the main domain is at siteground and the subdomain is at softr.io. <br /><br />I am using this for authentication, so when someone logs into the main domain, he/she can also access the login session on the subdomain. <br /><br />softr.io cannot add PHP code, so I can only use JavaScript on the subdomain. <br /><br />I used the following cookie code:</p><p><br /></p> <p><code>setcookie($cookie_name, $cookie_value, $expiration_time, '/', $subdomain, true, true);</code></p> <p>It shows the cookie in the application tab of the developer tools, but is not accessible in JavaScript via document.cookie. <br /><br />Is there anyone here who has tried this type of task and can guide me. <br /><br />I researched for hours but couldn't figure it out. </p><p><br /></p>
P粉046878197P粉046878197486 days ago536

reply all(1)I'll reply

  • P粉130097898

    P粉1300978982023-08-01 00:49:38

    The seventh parameter of setcookie is the HTTP Only flag.

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

    If you want to read it using client JS, please turn off this security feature.


    reply
    0
  • Cancelreply