PHP, SSL, File Output and Internet Explorer Error

While working on a project, everything was working on our beta site just fine.  Once we moved the project to the production site, we ran into an issue on a page that exported a csv file of information inline.  The only difference was that the production site was running SSL.

The basic situation is as follows.  A script written on PHP, running on Apache, through a SSL connection is dynamically generating a file (in our case a csv) and then sending it to the client.  This works correctly through Firefox, but returns an error in Internet Explorer.  The error returned is:

Internet Explorer cannot download <url of link>

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 hint, no matter how many times you try again later, it will not work.  I started with this code:

header("Content-type: application/csv\n");
header("Content-Disposition: attachment; filename=\"$filename\"; size=$size");

After much research, I found the way to fix this is through the Pragma header, making sure it’s anything BUT off-cache.  Once I add a new header, it worked fine through both Firefox and Internet Explorer:

header("Content-type: application/csv\n");
header("Content-Disposition: attachment; filename=\"$filename\"; size=$size");
header("Pragma: turn-off-cache", true);

I just changed it to turn-off-cache, but anything typed in instead of off-cache would work fine.

  1. I found your soution to be exactly what I needed to solved the problem I was having. Thanks!

  2. Thanks a lot, my production server works just fine now.

  3. Thanks you for sharing your experience – that saved my day. Thanks.

  4. Dude! Thanks.

    You saved me hours of time googling/debugging a script.

  5. Another huge thanks! It would’ve taken me hours upon hours to find this work-around.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>