Jump to content

Archived

This topic is now archived and is closed to further replies.

mganesh

File upload and Session variables problem

Recommended Posts

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.

[b]page1.php :[/b]
session_start();
session_register("username_session");
session_register("fullname_session");
$_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)

[b]page2.php :[/b]
session_start();
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 ?

Share this post


Link to post
Share on other sites
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:

<?php
session_start();
$_SESSION['name'] = 'bob';
echo $_SESSION['name']; <--- WILL DISPLAY
?>
<?php
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

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php
session_start();
$_SESSION['name'] = 'bob';
echo $_SESSION['name']; //<--- WILL DISPLAY
?>
<?php
echo $_SESSION['name']; //<--- WILL NOT DISPLAY
?>[/quote]

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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.