sudo rant

Original thoughts from some dude who likes graffiti, drag racing and PHP.

Subscribe to feed Latest Entries

SWFupload cannot write data after upgrade to PHP 5.3

Posted by Ben Harold
Ben Harold
Ben Harold has not set their biography yet
User is currently offline
on Thursday, 13 October 2011
in Web Development

The Upgrade - PHP 5.2 to PHP 5.3

If you provide me with a better tool, I'll use it. I recently upgraded a client's server from PHP 5.2 to PHP 5.3 to be able to use dynamic static calls in my code. Yes, there are PHP 5.2 compatible solutions to my problem, but this code is much cleaner and, quite frankly, I like it.

The Problem - SWFupload Doesn't Work Anymore

My client contacted me the next day and told me that the PHP 5.3 upgrade had broken Multiupload for VirtueMart, an extension that saves him a lot of time. Upon looking into it, I found that rather than being built on awesome HTML and JavaScript, it was built with stupid crappy Flash, specifically with a tool called SWFupload. I installed the extension on my Joomla development environment and switched between PHP 5.2 and 5.3. Sure enough, I was getting a 303 "See Other" error whenever an upload completed. The files were being uploaded, but they weren't being saved.

How Sessions Play a Role

After I figured out how to turn debug mode on for swfupload, one of the first things I noticed was that the session handling wasn't right. The context of the session was changing between requests in PHP 5.3, whereas it was the same between requests in PHP 5.2. Not only was my session data disappearing, but the user-agent string changed. In PHP 5.3, the debug data stated that the user-agent was Adobe Flash, whereas it was returning as Firefox under PHP 5.2

And of course, Cookies come into the pictures

Long story short, the solution to the session issue involves cookies...sort of. In PHP 4.3.0, a new runtime configuration option called use_only_cookies was introduced. This option, when set, prevents sessions from being started based on anything besides the cookie value of the session ID. In PHP 5.3.0, the default value of the use_only_cookies option changed from 0 to 1. What this means is, no matter how many hours I spent trying to force a specific session by passing the ID or name to the session handler, the session handler didn't care. It was like "sure, yeah, uh huh...what's the cookie value?" Technically speaking, the Adobe Flash script was actually making the HTTP request to save the data, not my browser. So PHP was looking at the cookie-based session ID being passed by Adobe Flash, instead of the session ID that I was trying to set manually.

The Solution

There are, of course, several different ways to solve this problem, but they all boil down to one thing: you need to set the use_only_cookies value to 0 if you want to start a session using a dynamic session.name or session.id. Here are some examples:

In your php.ini file:

session.use_only_cookies = 0;

In your .htaccess file:

php_value session.use_only_cookies "0"

session.use_only_cookies

At runtime:

ini_set('session.use_only_cookies', 0);

Conclusion

Upgrading to PHP 5.3 isn't such a daunting task, as long as you're armed with the right information. The only other issue that I ran into was the presence of depreciated function messages, but those don't appear under normal deployment server conditions.

0 votes
Hits: 392 0 Comments

Steve Jobs - Insanely Great or Greatly Insane?

Posted by Ben Harold
Ben Harold
Ben Harold has not set their biography yet
User is currently offline
on Thursday, 06 October 2011
in Apple

I remember a MacAddict magazine that came out right after Apple acquired Next. Steve Jobs was on the cover with a caption that read "Insanely Great or Greatly Insane?" And when he yanked the disk drive from the iMac, there were a hell of a lot of people out there for whom he quickly hit the "greatly insane" end of the spectrum. Now, less than 15 years later, you'll be hard pressed to find an intelligent person who can overstate his contributions to humanity. Yesterday we lost not only an American hero, but a world hero.



Some people call me an Apple fan boy, other people call me a Mac evangelist, but I'm neither. I don't wait in line outside of the Apple store for the latest iPride to come out, and I couldn't care less what kind of crappy computer you buy. I need one that works. That's why I use a Mac. It's the same reason I have an iPhone. When I buy a tool, I get the good shit, and Steve Jobs certainly knew "good shit." You will be missed.

Oh yeah, I almost forgot. In addition to kick-starting the personal computer revolution and building the most valuable company in the world, he was also a key player in reinventing the media distribution business for the online era, and he started a movie company that was so successful that Disney's purchase of the company made Steve the #1 shareholder...what an underachiever.

Tags: Steve Jobs, Apple
0 votes
Hits: 431 0 Comments