Page 1 of 1

A nasty bug in PHP?

Posted: Thu Jun 01, 2006 4:39 pm
by pyc
Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


try this code, you'll have to have file named picture.gif in the same directory where is the script executed...

Code: Select all

<?
$n = $_SERVER[DOCUMENT_ROOT].'/test.txt';
if (file_exists($n)) {
    $f = fopen($n, 'r+');
}    
else {
    $f = fopen($n, 'x+');
    fwrite($f, '0');
    rewind($f);
}    
$d = fread($f,5);
$d++;
rewind($f);
fwrite($f, $d);
fclose($f); 
//header('Content-type: image/gif');
//readfile($_SERVER[DOCUMENT_ROOT].'/picture.gif');
?>
You'll see no output except one variable in file test.txt is incremented by one and written back to file. I made this for counting purposes...

Now de-comment last two lines. Now picture.gif shows in browser which is intended, but the incrementation of variable is now by 2, always when you load script!!! I really can't explain this.... Can you? I please you people to try yourself...

Strange enough, it seems that there's no such error on Windows PHP ... I tried it on Linux, PHP 4.4.2


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Jun 01, 2006 5:59 pm
by Weirdan
I really can't explain this.... Can you?
write the contents of $_SERVER array to the log file, then analise the log. It could be caused by browser sending two requests for some reason (related to IE image flicker problem or something)

Posted: Fri Jun 02, 2006 1:59 am
by pyc
adding these headers into the code

header('Content-length.....
header('Expires:....

..solved the problem, but I still don't see how :)