Unsetting HTTP headers in PHP
Posted on 2008-08-06 - Comments
I just came across a subtle issue affecting Internet Explorer users (well, fancy that!) and HTTPS connections.
One of my clients has a site that downloads a series of results as a CSV file, which they open in Excel. Unfortunately, Internet Explorer was refusing to download the file, and was presenting an error message reading "Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found."
To add to my confusion, this was happening on the live server (PHP4), but not on my dev server (PHP5) which both use the same code.
In the end, I happened upon a Microsoft Knowledge Base article that explained the problem. Basically, IE obeys any "no-cache" headers you send to the browser. Without caching the file, Office applications cannot open the file when served over HTTPS.
How to solve the issue? Remove the cache header(s) – but how?
The PHP manual doesn't make it entirely clear, and I found the solution by accident. To remove a header, use the same syntax as for setting a header, but only include a space after the colon.
For example, for the "Pragma" header:
header('pragma: ');
Note: You must include the space after the ":" or the header will not be unset.
- Next generation console wishlist 2013-02-18
- Digital conversations preserved 2011-02-21
- Pastel de Nata recipe 2011-01-10
- Fixing a bricked D-Link DSL-G624T 2010-01-22
- Learning PHP - Part 6: functions 2009-11-03
- Learning PHP - Part 5: your first dynamic web page 2009-11-03
- Learning PHP - Part 4: controlling flow 2009-11-02
- Symptoms of a Wordpress hack 2009-11-02
- Learning PHP - Part 3: array basics 2009-10-26
- Learning PHP - Part 2: variable basics 2009-10-25
- Learning PHP - Part 1: introduction 2009-10-24
- Unsetting HTTP headers in PHP 2008-08-06
- Intermittent 1px gap in Firefox 3 2008-07-30
- Understanding Linux file permissions 2008-07-29
- Step by step: Moving code between Subversion repositories 2008-07-23
- Novell client on OpenSuse 10.3 2007-10-08
- Removing Windows from Apple's Bootcamp 2007-10-01
- HTTP authentication in PHP 2007-06-12
- Microformats and me 2007-06-11