Caution: NERD TALK AHEAD
A couple years ago, I created a request system for my department which would allow users to register their teaching preferences. This wasn’t really anything new, many other people have done it (I did it for my department at University of Florida years ago). In the years since, I’ve tweaked it and added features, but it’s been essentially unchanged.
On Tuesday, our department’s primary user of the system pointed out a bug in the way it handled new course requests. I went in and fixed the bug that afternoon. No problem.
But the next day, she told me it was not working right. I thought maybe it was a similar minor error. Nope — it was downright broken.
Here’s the problem I was getting:
When the user tried to download a spreadsheet of requests, the system spit out an error indicating that the header (which tells your computer that a file is on its way) had already been sent.
This was very puzzling, as I had not changed anything having to do with headers. Nonetheless, I started tracking the error back by forcing it, moving the code that replicated the error up the program chunk by chunk until I figured out that the initial headers were being set very early in the program.
In fact, they were being set when the program used “include” to grab a file of subroutines stored externally. Now I was really mystified — this shouldn’t yield headers at all. So finally I found where the error was being generated, but I had NO idea why.
Then I remembered: yesterday I got a message from my web host that the PHP on my servers needed to be upgraded to 5.3. “Sure thing,” I said as I clicked the upgrade button. Dammit.
Finally I discover that the error code I was getting showed where the mystery headers were being generated. It was at the end of the file. After the ?> which closes the program.
That’s right, upgrading PHP meant it was now unable to ignore two blank lines at the end of the file. Bang head on desk for five minutes. Delete two blanks lines. Revel in properly working program.
“C’mon you apes, you want to live forever?!”