Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Javascript Cookies from a subdomain

On a subdomain -- a.test.com -- I'm trying to read the cookies set at .test.com. If I use document.cookie in JS, all i'm getting are the cookies from a.test.com. What is the syntax or route to read the cookies from .test.com?

I'm pretty certain you can read up -- from sub domain to fqdn -- but you can not read down -- fqdn to sub domain.

Thanks!

like image 315
zmonteca Avatar asked Nov 06 '09 17:11

zmonteca


1 Answers

While setting the cookies at test.com example.com, make sure that you specify the cookie domain as ".test.com" ".example.com".

For example:

your_key_name=your_key_value;domain=.example.com;expires=...
like image 52
Ates Goral Avatar answered Oct 13 '22 21:10

Ates Goral