Detecting double hits from Firefox

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

The short version: I'd like to detect when Firefox make a
double request for my images so that I don't double log it.

The details.  When a person in FF enters a url directly
to an image, FF would like to display a mini version of
the image just to the left of the URL.  In my particular
situation, this results in a double hit to the server.

When I receive a request for a certain set of images (ie.
non thumbnail images), then I'd like to log that. So what
I did is to have a apache rewrite
/imageDir/imageName.jpg to

jpgPassThru.php then writes out certain header information
to prevent cacheing (these pics are not very large),
and then does a readfile() on the image, and logs the
access.  And this works fine.

In the course of testing, however, I found that when
I directly entered the url into the address bar (as opposed
to clicking a link on the page) from Firefox, two hits would
result to the server from FF within two seconds of each
other (but usually much faster).  Unfortunately, I am on
a server which cripples my log file functionality within
Apache (I'm on so it's a real annoyance
to analyze what is going on.  I'm hoping that someone
has experience with this situation and can point me to
a simple means of detection.

Csaba Gabor from Vienna

Re: Detecting double hits from Firefox

Quoted text here. Click to load it

Isn't that the location for displaying the so-called favicon?

Quoted text here. Click to load it

So what do you *really* want to do? On one hand, you say you'd
like to know "what's going on", on the other hand you want to
exclude certain events from logging. Why? What's the purpose of
the logfile?

You could probably start a session on the first request, write
down that the image has been requested, and log the access


Re: Detecting double hits from Firefox

El 18/04/2010 1:55, Csaba Gabor escribió/wrote:
Quoted text here. Click to load it

Are you sure that the problem you are trying to fix exists in the first
place? When you load a picture in Firefox it displays a thumbnail of the
image as pseudo-favicon, but I've never noticed that it reloads the
document from the server; not even in images that are configured to skip

You should verify the issue in different client set-ups. It could be due
to a misconfigured proxy, a paranoid security suite or a poorly written
Firefox extension...

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor satinado:

Re: Detecting double hits from Firefox

On Apr 19, 1:45 pm, "=C1lvaro G. Vicario"
Quoted text here. Click to load it

Upon subsequent testing, I can confirm that the problem exists, and
it is most peculiar.  I have tested against IE 6 and FF 1.5 on
Win XP Pro, and IE 8 under Vista.

The observed behaviour specifically is that when a .jpg is entered
into the address bar of FF1.5, then immediately afterwards AND
every time that window receives focus anew, FF issues a request
for the .jpg file (at least with cacheing turned off).  I'll
install a more recent FF and see if this exists there, too.

The only difference that I detect in the requests is that the
initial one receives the following HTTP_ACCEPT (as an
unbroken string):

and each subsequent request has an HTTP_ACCEPT of:

For comparison, the IE6 and IE8 HTTP_ACCEPTs are:
image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/, application/,
application/msword, application/x-shockwave-flash, */*

image/jpeg, application/x-ms-application, image/gif,
application/xaml+xml, image/pjpeg, application/x-ms-xbap,
application/x-shockwave-flash, application/,
application/, application/msword, */*

In addition, the issue only pops up if the url is
entered directly into the address bar of FF.  If I
click on a link to the image or if I stuff the image
into a popup window (by virtue on an <img ...> element)
I don't see this arise.  Therefore, the chances of
encountering this behaviour are fairly small, I

However, I have had a rethink of my more global
issue (what do I really want to accomplish?) along
the lines of the prior responder, Felix, and I
am planning to reinstitute cacheing, which I expect
will moot the observed behaviour.  Nevertheless,
I tested with code along the lines of:

// send all headers but the size
$now = gmdate("D, d M Y H:i:s", time()) . "GMT";
header("Content-type: image/jpg");
header("Last-Modified: $now");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=3D0, pre-check=3D0", false);
header("Pragma: no-cache");

// put the request into a file
$phpinfo = ob_get_clean();
$base = "imgreq";
while (file_exists($f = $base . rand(1,9999)));
file_put_contents($f, $phpinfo);

// output the image
if (!$file  || !file_exists($file)
            || (($size=3Dfilesize($file))<10) {
  // bad request - show some default img
} else {
  header("Content-Length: $size bytes");


Site Timeline