Avatar of pillmill
pillmill
 asked on

$_SESSION lost?

Is the session value being lost in the following:

parent:
<?php
if(!empty($_SESSION['name'])) echo ($_SESSION['name']);
?>

<html>
<form>
<iframe src="child.php"/>
</iframe>

</form>

</html>

Open in new window


child:
<?php
 if(!empty($_FILES)) {$_SESSION['name'] =$_FILES['file']['name']  ;
   }
?>
<html>
<body>

<form action="child.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

Open in new window



Can the $_SESSION value be retrieved by the parent?
Web ServersWeb BrowsersWeb Development Software

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
pillmill

ASKER
Thanks. I added session_start() to the parent:
<?php
session_start(); 
if(!empty($_SESSION['name'])) ($_SESSION['name']);
?>
<html>
<form>
<iframe src="child.php" />
</iframe>
</form>
</html>

Open in new window


Session variables still seem to be unavailable.
How can I access $_SESSION set by the child?
Dave Baldwin

You have to add it to ALL pages, not just the parent.  It has to be identified on each page that is loaded.  That includes the child page.  

The PHP page on the server only 'sees' the session during the time it is processing the PHP code.  When it gets to the browser, the server is already done with the session for that page.  It's not a 'sticky' kind of thing.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23