Solved

$_SESSION lost?

Posted on 2012-03-19
3
268 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
  • 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
website issue in Firefox 8 72
http to https 3 62
firefox 50 saying your connection is not secure to every website 13 162
What is the best password manager? 12 150
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

831 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