NotionCommotion Posted November 30, 2014 Share Posted November 30, 2014 I expected the following script to display a single cookie on the main page (cookie_2, and both the main page cookie and the subdomain cookie (cookie_3) within the iframe. In actuality, the main page was as expected, but the iframe only displays cookie_3. Can anyone explain what I am witnessing, and why the subdomain wouldn't be able to access the cookie set in the parent? <?php setcookie("cookie_".count(explode('.', $_SERVER['HTTP_HOST'])), 'Hello from '.$_SERVER['HTTP_HOST']); echo('<pre>'.print_r($_COOKIE,1).'</pre>'); ?> <iframe src="http://test.mysite.com/testing/cookietest.php"></iframe> Quote Link to comment Share on other sites More sharing options...
kicken Posted November 30, 2014 Share Posted November 30, 2014 Try setting the domain parameter of the cookie as well to your base domain name. According to the RFC for cookies: If the server omits the Domain attribute, the user agent will return the cookie only to the origin server Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted November 30, 2014 Author Share Posted November 30, 2014 Thanks Kicken, I had just stumbled upon this and am starting to experiment. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.