A nasty bug in PHP?
Posted: Thu Jun 01, 2006 4:39 pm
Weirdan | Please use
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]
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');
?>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]