0

I have set a cookie from domain (.example.co) and its .NET platform & reading those cookie from drupal site(test.example.co).

While retrieving it shows empty, I have used $_COOKIE.

This link suggests it is possible, also we are setting domain name while creating cookies? Is it possible to use while retrieving cookies?

Also i have found this link, is that interrelated?

3 Answers 3

2

You need to provide an appropriate value for $cookie_domain in settings.php.

e.g.

$cookie_domain = 'example.co';

That will allow you to set/retrieve cookies from example.co on foo.example.co, and vice versa.

3
  • i have updated my cookie domain to (.example.co) i can able to access my drupal session cookies which are in (.example.co) but unlikely other cookie which am required :(
    – Prasanth R
    Commented Apr 11, 2018 at 9:56
  • This isn't a Drupal thing, it's just how cookies work; whatever sets this other cookie just needs the same domain=example.co set on it
    – Clive
    Commented Apr 11, 2018 at 10:03
  • i have updated my query.
    – Prasanth R
    Commented Apr 13, 2018 at 5:04
0

In order to use other subdomains' cookies, you need to set both site's cookie domain to .example.com.

3
  • 1
    You need to remove the leading . to ensure greatest compatibility across older/modern browsers. If you're not concerned with supporting older browsers the leading . is ok, but will be ignored by the browser anyway. So might as well remove it altogether. See RFC 2109 and RFC 6265 for the low-level explanations
    – Clive
    Commented Apr 11, 2018 at 10:13
  • Ah for me that's quite conflicting, my team and I tried to share cookies across subdomains but couldn't get it to work unless we had the leading period. We try not to support older browsers, so I guess for us at the mo, the leading period is ok. Would you suggest we give it another shot? Commented Apr 11, 2018 at 10:53
  • To be honest I’m just paraphrasing the RFCs and some related info (as I’ve understood them), I guess your mileage may well vary depending on circumstance
    – Clive
    Commented Apr 11, 2018 at 12:38
0

Thanks all for you reply,

Finally reason has been found, since there is an DOT(.) in the cookie name set. It cannot be retrieved.

https://harrybailey.com/2009/04/dots-arent-allowed-in-php-cookie-names/

Not the answer you're looking for? Browse other questions tagged or ask your own question.