user168715
user168715

Reputation: 5579

sharing cookies across domains on same host

I'm trying to maintain a web site spread across two domains with the same host (one is actually in a subfolder of the other):

www.a.com  -> /.../public_html/
www.b.com  -> /.../public_html/b/

I have one script on a.com, let's call it public_html/readcookiedata.php, which reads in some session variables from a cookie. Another script on b.com, let's say public_html/b/index.php, needs to also read this cookie.

Right now index.php tries to require_once(../readcookiedata.php).

This works great if I visit www.a.com/b/index.php: the cookie is read OK. However, if I browse to there directly, www.b.com/index.php, the cookie isn't read.

What's the best way to fix this problem? Is there a way for a.com to allow b.com to read its cookies? Or some way to configure the host to treat all requests to b.com as if they were for a.com/b/ instead?

Upvotes: 1

Views: 999

Answers (1)

Amber
Amber

Reputation: 526543

No. Cookie security is built into the web at a browser level; browsers literally won't allow you to read data for cookies from other domains on pages served by a different domain.

Upvotes: 4

Related Questions