Tutorial :Send a Variable to an IFrame's Parent in PHP?


How can I transfer an array from an IFrame running a php script, to the parent PHP of the IFrame?

I have an Array of strings in PHP that need to be transferred to the main window so that when the iframe changes pages, the array is still stored.

I could use a cookie for this, though I'm not sure that would be the best idea.



Like Tim Hoolihan said, PHP is a server side language that is only responsible for generating the HTML before it is sent to the browser. Meaning once the page shows up in your browser window, PHP has done it's part.

However, with that said, if you control both the "parent" page and the page being iframed, you can json_encode the array in the page being iframed and set it to Javascript variable, then on load pass it to a Javascript function on the parent page (assuming not violating any browser/domain sandbox constraints). At that point you can do whatever you want with it.

Take a look at jQuery for your core Javascript/Ajax needs.


you can't do that in php. iframe is like a new browser window, so they are separate requests. separate requests can not transfer data between each other in a server side language.

if you give some detail as to what you're trying to accomplish, there may be another way around the issue that someone can suggest.


if you control the iframe, you can save the array in a session variable and make the parent do an asynchronous call to retrieve the array from session.

however Jordan S. Jones solution with only javascript works as well

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »