This was the real code. You notice I forgot fget's number
<?php
$fd=fopen("CHAT.htm", "r");
while(!feof($fd)) {
$tmp = fgets($fd, 1024);
}
fclose($fd);
$fp=fopen("CHAT.htm", "w");
fputs($fp, "$username: $msg");
fputs($fp, "\n<BR>\n");
fputs($fp, $tmp);
fputs($fp, "\n<BR>\n";
fclose($fp);
?>