Jump to content

carry cookies into an iframe


toolman

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/291252-carry-cookies-into-an-iframe/
Share on other sites

  • 2 weeks later...

 


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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.