Solved

$_SESSION lost?

Posted on 2012-03-19
3
271 Views
Last Modified: 2012-03-25
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?
0
Comment
Question by:pillmill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 37740926
Without session_start() at the top of each and every page, you effectively do not have session variables because session_start() sets up and refetches the session id which is used to identify the variables for your session.  Without session_start(), you do not have a proper session id.

If both files are on the same server and sessions are setup properly, then parent and child are in the same session because they are in the same browser at the same time and can see the same session variables.

http://us.php.net/manual/en/function.session-start.php
0
 

Author Comment

by:pillmill
ID: 37741073
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?
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37743672
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.
0

Featured Post

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question