Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Favicon when passing PDF? 1

Status
Not open for further replies.

OsakaWebbie

Programmer
Feb 11, 2003
628
JP
Hopefully an easy question. I have an application in a subdirectory, whose favicon is different from that of the parent directory so I have to link it explicitly. For normal code that echoes HTML, I can just do this (outside PHP, or with an echo statement):
HTML:
<link rel="shortcut icon" type="image/x-icon" href="[URL unfurl="true"]http://mysite.com/subdirectory/favicon.ico">[/URL]
But in one file I generate a PDF that I then send to the browser like this:
PHP:
header("Content-Type: application/pdf");
header("Content-Transfer-Encoding: binary");
@readfile("$fileroot.pdf");
In this case, how do I specify the favicon? I've looked all over the internet for the syntax of header() for that, but I can't find it.

If it's not possible in header(), perhaps there is another way? Maybe something I can set in php.ini or .htaccess or something - everything in that subdirectory should use the favicon.ico there. (PHP is running as FastCGI.) The server is a VPS, so I have no restrictions on what I can do.
 
Hi

As favicon is related to HTML, not to HTTP, [tt]header()[/tt] can not help.

As favicon is handled on client side, neither php.ini can help.

As for favicon requests the Referer HTTP request header is not sent ( at least not in FireFox ), neither the workaround I had in mind would help.

A pale idea anyway : open the PDF file in an [tt]iframe[/tt]. That way you can set the favicon to the containing HTML document. But I would not do that if the visitors supposed to save the PDF file as the dumb novice ones will keep saving only the otherwise empty HTML.

Feherke.
[link feherke.github.com/][/url]
 
don't know much about favicons but can't you just rewrite the request url in a server side htaccess file for that subdirectory?
 
Hi

Justin said:
don't know much about favicons but can't you just rewrite the request url in a server side htaccess file for that subdirectory?
Yepp, this was my first thought too.

But thinking again, that would solve nothing, as there is only one default favicon : the one in the root directory. If no [tt]link[/tt] tag specifies an alternative icon, the same default will be served regardless the document's path.

Feherke.
[link feherke.github.com/][/url]
 
really?

an over-engineered solution perhaps (and i have no idea whether this will work:

1. in your application:
a. start a session.
b. store the page request in a session variable.
2. in a root htaccess, redirect favicon.ico to favicon.php
3. in favicon.php open a session and test for the last requested page. if the last requested page is in the lower sub-directory then serve up one favicon, if not then another.
 
Thanks to both of you for trying to help. Apparently there is no straightforward, "normal" solution, and it's not important enough to do a convoluted workaround. (Regarding the iframe idea - my er...novice users WILL try to save it, and I want it to be easy to do so.) If it ends up being more of an issue later, I might try the over-engineered way, but at least at the moment it's probably overkill.
 
the 'over-engineered' way is only two or three lines of code. so do post back if you want to try that solution.
 
What makes that solution sound difficult to me is that the stuff in the root level directory is not code I wrote (a Joomla website), and I'm not sure I want to go down the path of figuring out how to write an override in the Joomla template to set the session variable (and whatever else might be needed, since as you said, this is untested). If that's easier than I think, let me know, but it sounds like the various parts of the equation become a bit of a dance.

At the moment the users are all people I know - I just thought it would be less confusing (even for me, who is one of the primary users) when looking at open tabs in the browser and such, if the favicon for the PDF was the same as other tabs in the application. If I get the opportunity to widen the user base (I'd like to, but that takes time that I don't currently have), I would choose a domain for it, so then the problem would solve itself.
 
Hi

I done some testing with a favicon served by a PHP script with [tt]Pragma: no-cache[/tt] HTTP response header. First I visited the page, then I modified the script to serve a different file as favicon and reloaded the page.
[ul]
[li]Arora, Epiphany FireFox, Midori, Opera, SeaMonkey - kept displaying the original favicon[/li]
[li]Chrome - changed the favicon to the new one[/li]
[/ul]
Not tested exhaustively, but as I observed [tt]Pragma: no-cache[/tt] makes FireFox to request the favicon each time, but it not changes the displayed one.

Just mentioned as related information. No conclusion.

Feherke.
[link feherke.github.com/][/url]
 
@OsakaWebbie

the solution would be to use an autoprepend in php.ini (or htaccess). i.e. completely bypass joomla and have the process sorted out long before joomla gets hold of things.

but given feherke's findings you might consider it a pointless tilt at a windmill anyway.

@feherke
good stuff! I wonder which browser is properly conformant?
 
Ah, in some ways Chrome shows signs of being more "conformant", as you say, for display. But I personally have no use for a browser whose developers all but ignored printing - in Chrome (last time I checked) there is no option to print backgrounds (and more and more images these days are background images), the "johnny-come-lately" Print Preview doesn't work right (it lies about what the print will actually look like), it insists on using its own PDF viewer instead of Adobe, and that viewer also seems to have been designed without thinking anyone would print anything (e.g. it is impossible to print actual size without it shrinking to fit in some arbitrary margins, which is disaster for some of the things I do). I would like to like Chrome, but I can't.

Okay, I'll stop griping now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top