Adobe Flex Upload +[PHP] Session + Firefox = Failure !

Well not quite but almost. Here’s my dilemma, I have a flex app that allows the user to upload files. My backend PHP script utilizes session variables to ensure the user has the appropriate credentials before proceeding with the upload. When ran under a firefox browser, it appears as though a brand-new session is created when flex calls the upload.php script.

Here’s a recap..
1) Flex app uploading a file via file.upload(request,"upload")
2) Upload.php check requires existing session vars to be present
3) When invoked via firefox upload.php has NO existing session variables
4) IE works great!! Yep, I can’t believe it either.

It *is* possible to pass the php session information (print("?".session_name().'='.session_id());) to the upload script but that’s not a viable option due to security concerns.

For now, I’ve coded up a hack around this problem, but I’m hoping to have some more time in the near future to investigate further.

Image cache and Adobe Flex

Okay, I kept running into the headache of images being cached within my flex application. I found a simple workaround, appending a URL parameter of the current time to the image’s path.

For example, the path img/simple.jpg becomes img/simple.jpg?date=12010103. Each time the page is refreshed, a new date parameter is generated, fixing our cache headache.

The flex code

url + "?d=" + (new Date()).getMilliseconds();

And the php code

$url . "?d=" . date("U");

Those two small take care of the images being cached.


I’ve decided to park my blog here at digital luminosity’s site. In keeping with the open architecture mindset I enjoy so much, I’ll be blogging my discoveries in RIA (Rich Internet Application) and embedded device development here. Hopefully this information will prove useful to fellow developers.