PHP: dynamic PDF generation problem with internet explorer, a solution

When generating a PDF or any other dynamic content using PHP you must be aware that Internet Explorer has a couple of bugs about dynamic content, for instance knowled base 234067.

My guess is that when downloading a dynamic PDF generated by a PHP page the plugin within Internet Explorer need to have access to the cached file in some way to work correctly.

 

My problem

I’ve recently migrated an old PHP application from a old messed up Linux server to a fresh installed CentOS. I spent days doing tests and everything was fine before the migration. After the migration the users started experiencing downloading problem with the PDF.

Guess? I did all the tests using Firefox instead of MSIE. I’m sure i’ve some differences into my Apache’s config file, maybe I didn’t enabled mod_expire or some other module.

 

The solution

Anyway this can be also easily fixed settings the Expire header and the Cache-Control header. The theory about this has been already explained in my previous article about howto control page caching with PHP. So, just add to your PHP script the following piece of code to have the browser cache the page for some seconds.

$offset = 10;
$expire = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
Header($expire);
Header('Cache-Control: max-age='. $offset.', must-revalidate');

test again, it should work.

 

PHP: dynamic PDF generation problem with internet explorer, a solution, 5.0 out of 5 based on 1 rating
GD Star Rating
loading...