Writing to $_SESSION Seems to Not Stick
Posted: Sun Jun 21, 2009 12:28 pm
Good afternoon! I'm trying to use $_SESSION for temporary storage between pages, but it seems that the write is being discarded. Can anyone tell me what I'm missing?
Typical output (the content of the Exception) looks like this:
Uploaded media to SESSION[0]: test image.gif; count is now 0
...and indeed, on subsequent pages there will be no entries in $_SESSION["Media"]. I don't understand how $_SESSION["Media[0]"] can be set to a value, yet count($_SESSION["Media"]) remain zero. I could use a pseudo-array (Media1, Media2, etc.), but surely that's not necessary.
I have no problem getting the file information, or creating the TempMedia object, and there's no error to indicate that the problem is in writing to $_SESSION. I know that sessions are working in general, because my security is working fine (thanks to help from arborint and kaisellgren
) This page is only accessible for signed-in users, so I know that a session exists.
Any ideas? Thanks!
Jonathan
Code: Select all
if (isset($_SESSION["Media"]))
$pos = count($_SESSION["Media"]);
else
$pos = 0;
$_SESSION["Media[$pos]"] = new TempMedia($fileName, $mediaName, $mime);
throw new Exception("Uploaded media to SESSION[$pos]: " . $_SESSION["Media[$pos]"] . "; count is now " . count($_SESSION["Media"]));Uploaded media to SESSION[0]: test image.gif; count is now 0
...and indeed, on subsequent pages there will be no entries in $_SESSION["Media"]. I don't understand how $_SESSION["Media[0]"] can be set to a value, yet count($_SESSION["Media"]) remain zero. I could use a pseudo-array (Media1, Media2, etc.), but surely that's not necessary.
I have no problem getting the file information, or creating the TempMedia object, and there's no error to indicate that the problem is in writing to $_SESSION. I know that sessions are working in general, because my security is working fine (thanks to help from arborint and kaisellgren
Any ideas? Thanks!
Jonathan