PHP Session & Iframe

$_SESSION, PHP, iframe, not getting the SESSION variables

Make sure that session_start() is on all the pages:

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

see PHP manual reference

To control the contents of the $_SESSION try to put in all ifreame pages the code:

<?php 
session_start();

echo '<pre>';
var_dump($_SESSION);
echo '</pre>';

How to transfer php session variables from a page to an iframe inside the page

What ever page is referenced in the iframe, if it exists on your the same domain will have access to the same session information on the hosting site so long as that page has session_start() called on it.

Example.

  page1.php 
<?php
session_start();
$_SESSION["HELLO"] = "WORLD";
?>
<html>
<iframe src='page2.php'/>
</html>

page2.php
<?php
session_start();
echo "HELLO ".$_SESSION["HELLO"]; // will output HELLO WORLD

This is only true for sites that have access to the same cookies and the same session store.



Related Topics



Leave a reply



Submit