Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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 also what gets printed. 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.

When the user hits 'print preview', this 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?

share|improve this question
    
Are these images presented in a standard img element? They aren't background-images for instance? I assume, from your question, that you don't have a print-only stylesheet? How is a user authenticated? –  w3d Jul 30 '12 at 13:58
1  
The user is viewing the images directly (i.e. example.com/private/chart.jpg), they aren't viewing them embedded within a HTML page. Authentication is a PHP session based login system. –  Tim Fountain Jul 30 '12 at 13:59

1 Answer 1

It seems that print preview doesn't have access to your current session, or just has a session on it's own. Or possible not even a 'browser' and just renders the page as an image towards a clientside app.

So I think your best bet is to use some other form of authentication for the images.

cookies? database? or provide a temporary full access page for printing without auth?

share|improve this answer
    
But if it was purely a problem with authentication wouldn't HTML pages (that required login) also be a problem? The OP states these print OK. –  w3d Aug 1 '12 at 11:46
    
indeed, I didn't see that before.. –  woony Aug 1 '12 at 13:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.