Internet Explorer Can't Open Files Via HTTPS: Try Removing The Pragma Header

| 1 TrackBack
While wrapping up a few bugs on one of my latest projects, Onyx, I encountered one of the most annoying and irritating IE nuisances to date.  Let me reiterate my hatred for Internet Explorer.  So here's the deal.  In PHP, I was serving up a few static files nestled away on the web-server.  The user would click a link, my PHP would fopen a file, and send it to the browser.  Simple enough, and this worked just fine on HTTP.  Then, I moved my new web-application to a production environment under HTTPS.  Suddenly, some downloads failed on IE with the following error:

"Internet Explorer cannot download [file] from [server]. Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later."

Here's a screen shot of the error from IE8:

ie-cannot-open-file-https.jpg


With a little digging, I tracked down the following support pages on microsoft.com that explain the problem:

It appears that Internet Explorer gets confused when it sees a Pragma and Cache-Control header together in the same response.  And, it has difficulties interpreting these headers properly over HTTPS.  As described on microsoft.com, "when Internet Explorer communicates with a secure Web site through SSL, Internet Explorer enforces any no-cache request. If the header or headers are present, Internet Explorer does not cache the file. Consequently, Office cannot open the file."  And, when you're using sessions in PHP, the PHP engine automatically by default inserts the Expire, Cache-Control, and Pragma headers in your responses as explained here.

In my case, the solution to this issue was to remove the Pragma header in my HTTP response.  In PHP, I forcefully unset the Pragma header with the following code-snippet:

header("Pragma: ");

This successfully clears the Pragma header in my responses, and all is well.  With this tweak, IE7 and 8 correctly handle my file downloads.

Did You Find this Helpful?

Did you find this post helpful, or at least, interesting?

  

About Mark

A Silicon Valley native, Mark Kolich is a full-time Software Engineer and a consultant for hire. A web technologies expert, his current focus is on building powerful and robust cloud-driven web-applications using Java, PHP, Perl, AJAX, DHTML, CSS, and JavaScript. His favorite programming languages are PHP, Java and JavaScript. He uses Linux, enjoys biking to work, loves building great software, and always writes elegant, readable, and maintainable code.

1 TrackBack

Onyx (beta) from Mark S. Kolich on November 6, 2009 12:15 PM

If you follow me on Twitter, you may have noticed I silently launched Onyx a few weeks ago.  In a nutshell, as described on the Onyx homepage ..."Onyx is a social file management tool I built to help me keep... Read More

Twitter (@markkolich)

Translate

About this Entry

This page contains a single entry by Mark Kolich published on October 22, 2009 10:50 PM.

Reliably Checking Windows Bitness (32-bit or 64-bit) With a Tiny C++ App was the previous entry in this blog.

Bundle Java (the JRE) and Launch a Java App with 7zip SFX! ... (Convert Java Apps to an Executable, sort of) is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.