Closed Bug 331126 Opened 14 years ago Closed 14 years ago

PHP script that generates an image gets called twice by Firefox

Categories

(Firefox :: General, defect)

x86
Linux
defect
Not set

Tracking

()

RESOLVED DUPLICATE of bug 304574

People

(Reporter: johanp, Unassigned)

Details

Attachments

(1 file)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.1) Gecko/20060126 SUSE/1.5.0.1-5.1 Firefox/1.5.0.1
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.1) Gecko/20060126 SUSE/1.5.0.1-5.1 Firefox/1.5.0.1

Using PHP it is possible to create dynamic images by creating an image stream. When an image generating script is called directly from the browser it is actually called twice for each time it is called.

Reproducible: Always

Steps to Reproduce:
A simple way to illustrate this is to run the following very small script. It creates an image and write a log text to a specified log file. Calling this script once through the browser will show two entries in the log.

Save the following script to a file and call it through some HTTP server (e.g. Apache)

<?php
DEFINE('LOGFILE','/tmp/fflog.txt');

$fp=fopen(LOGFILE,'a');
fwrite($fp,'- Calling script at time: '.time()."\n");

$w=200;
$h=100;

$im = imagecreatetruecolor ($w, $h); 
$black = imagecolorallocate ($im, 0, 0, 0); 
$lblue = imagecolorallocate ($im, 200, 255, 255); 
$red = imagecolorallocate ($im, 200, 0, 0); 

// Create a filled rectangle witha  red cross
imagefilledrectangle($im,0,0,$w-1,$h-1,$lblue);
imagerectangle($im,0,0,$w-1,$h-1,$black);
imageline($im,1,1,$w-2,$h-2,$red);
imageline($im,1,$h-2,$w-2,1,$red);

header ("Content-type: image/png"); 
imagepng ($im); 

fclose($fp);

?>

Actual Results:  
Calling the script will show a rectangle with a red cross and also log two text string to the specified log file. This shows that the PHP file have been called twice by firefox even though the file has only been called once.

Expected Results:  
The log file should only show one entry since the file is only called once. 
The included script works fine in both Opera and IE.

There is no workaround for this problem as long as the image script is called directly.

Saving the image to a file and then displaying the image with an <IMG> tag will work fine.
Note: The LOGFILE define should be adjusted so that it points to a file that can be written by the Apache process.
Sounds like this one: Bug 304574.
It does.
Can you provide the HTTP data sent during the two requests? (e.g. Using the livehttpheaders extension.)

*** This bug has been marked as a duplicate of 304574 ***
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.