Jump to content


File upload and Session variables problem

  • Please log in to reply
2 replies to this topic

#1 mganesh

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 29 May 2006 - 08:08 AM

Here is a peculiar problem that I am encountering

This problem is ONLY IN FIREFOX and NOT IN IE (Important !)

I have two pages page1.php, page2.php

Here are the exerpts from the two files.

page1.php :
$_SESSION["username_session"]=<value from database>
$_SESSION["fullname_session"]=<value from database>

There is also a form for uploading 5 files (MAX_FILE_SIZE is mentioned as a hidden field with 1000000 as the value)

page2.php :
echo $_SESSION["username_session"]."<BR>";
echo $_SESSION["fullname_session"];
echo $_SESSION["session_variable_created_in_earlier_page"];

The file info posted from the previous page is available here, and also the session variable created on another previous page, but not the session variables created and assigned in page1.php.

The observation: Session variables created on the same page where a file upload form resides, vanish in the next page. This is observed only in firefox and not internet explorer. In IE everything is just fine.

Has any one come across this problem ?

#2 glenelkins

  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 29 May 2006 - 10:03 AM

i suppose it all depends on where your session_start(); is in each file.

You cannot access $_SESSION[] from inside seperate <?php ?> tags. For example:

$_SESSION['name'] = 'bob';
echo $_SESSION['name']; <--- WILL DISPLAY
echo $_SESSION['name']; <--- WILL NOT DISPLAY

As you can see, you cannot take the value of $_SESSION['name'] in the second section as session_start() is not in the same <?php ?> as the echo command.

I hope this makes sense
http://thewebsolutionprovider.com - A Solution For Everything Web!

#3 Ferenc

  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 29 May 2006 - 05:38 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php
$_SESSION['name'] = 'bob';
echo $_SESSION['name']; //<--- WILL DISPLAY
echo $_SESSION['name']; //<--- WILL NOT DISPLAY

You are wrong, the code above displayed bobbob for me, both locally and remotely(IE and firefox).

If what you said was true, why even have sessions?

The key to sessions is to start them correctly on every page. Most people with session issues fail to do that.
Everything you want to know is here.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users