toolman Posted September 24, 2014 Share Posted September 24, 2014 Hi, I have a page that carries through cookies and displays a different image/banner depending on the cookies. The URLs look something like: http://www.website.com/?agent=agent-name I now have a page with an iFrame on displaying the URL: http://www.website.com/?agent=agent-name If I access http://www.website.com/?agent=agent-name normally, they cookies carry through and the banner shows, but it doesn't if I access it through the iFrame. Is there a way of carrying the cookies into the iFrame? Also the URL that the iFrame is on is different to the content of the page inside the iFrame. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/291252-carry-cookies-into-an-iframe/ Share on other sites More sharing options...
.josh Posted October 3, 2014 Share Posted October 3, 2014 Also the URL that the iFrame is on is different to the content of the page inside the iFrame. Different...what? Domain? I assume that's what you meant, because if the parent/child pages were on the same domain, they could share the cookies no problem (assuming you are setting the cookies to root domain name with no subdomain or path). So, if you meant that they are on diff domains, then the iframed page cannot read the cookies from the parent page, as this is considered cross-site scripting. To get around this, you can do the following: On the parent page: - read the cookies on parent page - append cookies as url params to the iframe url - generate the iframe with the url w/ the params. Then on the iframed page: - read url params from the url - store them in cookies (or do whatever w/ them). Note that the iframe page will store them in its own cookies scoped for that domain, which would be separate cookies from the parent page's domain. Quote Link to comment https://forums.phpfreaks.com/topic/291252-carry-cookies-into-an-iframe/#findComment-1492616 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.