Unable to print login-required images in IE
- by Tim Fountain
I have some images in a section of a site that require the user to be logged in in order to view. These images are served by a PHP script, which checks the user's login state and if valid, serves the binary data with the appropriate headers. This all works fine.
The issue comes when a user tries to print one of these images. In Internet Explorer, when they go to print preview they get the broken image box with a red cross in the corner instead of the actual file. This is what gets printed also. All other browsers can print the images without issue.
I have some images elsewhere on the site that are also served via. PHP but these don't require a login. These print fine.
The PHP-powered HTML pages on the site that require a login also print fine in IE. It's just login-required images.
The user hitting print preview does not seem to result in additional HTTP request to the server for the file. However I do see an additional HTTP request a few seconds later that comes from the same IP (may or may not be related), This request includes no host header, no REQUEST_URI and no user agent.
The 'please login' page sends an appropriate 403 header. I've also added a far-in-future expires header to the image response itself to ensure that browsers can serve/print the files from their own cache but this hasn't made any difference.
Why can't IE print the images and what else can I do to investigate or fix the problem?