tagline in progress

Using Session Cookies with SWFUpload, Despite the Bug in Adobe’s Flash Plugin

While adding SWFUpload to a current project, I ran into a fairly well-known Flash bug. In this case, it prevented the logged-in user from re-establishing their session values.

Depending on your situation, the solution is simple enough: pass along the Session ID during the file upload, re-establish the session manually before trying to process any data that may be located in the Session. The code suggested in the forum looks something like this:

if (isset($_POST["PHPSESSID"])) {

In SWFUpload, all you need is to add a post parameter.

In my case, the Session was already started and changing the session ID did nothing. The trick is to use session_write_close() to end the existing session, set the new ID, and start it again. My code looks like this:

if (isset($_POST["PHPSESSID"])) {
    session_write_close();             // End the previously-started session
    session_id($_POST["PHPSESSID"]);   // Set the new session ID
    session_start();                   // Start it

Of course, the best solution would be for Adobe to fix the problem, but hopefully this explanation will help others until then.

Categorised as: Programming

Comments are closed.