Well, I made this guestbook script, and it worked fine when the comments were just getting stuck on the end of the file, but then I decided it would be a lot better if the comments were sorted newest-first instead. The logical way to do this, I guessed, would be to store the commments in a seperate text file, and stick them on the beginning instead of the end. However, my code doesn't work right: When a new comment is posted, the new comment appears like so:
(ALL older comments)
(New comment)
(ALL older comments AGAIN)
Anyway, here's the code I'm using. NOTE: Before using this, you have to make a file called "talk.txt", with a file length of more than 0 bytes,
<html>
<head>
<style>
body{ background-color:white; color:black; font-family:verdana;
}
a:link{ color: red;
}
a:visited{ color: red;
}
a:hover{ color: red;
}
a:active{ color: red;
}
input {
border: 1px solid #333333;
background-color: #FFFFFF;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 8pt;
color: #000000;
padding: 0px;
}
textarea {
border: 1px solid #333333;
background-color: #FFFFFF;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 8pt;
color: #000000;
padding: 0px;
}
</style>
<title></title>
</head>
<body>
<font size="-2">
<?
if ($nm==null){
?>
<form action='talk.php' method='post'>
name:<br><input type='text' name='nm' border="0"><br><br>
comment:<br><textarea style='height:100;width:130' name='co'></textarea><br><br>
<input type='submit' value='post'></form>
<?
}else{
$nm = strip_tags($nm);
$co = strip_tags($co);
$filename = 'talk.txt';
$fp = fopen($filename, "r+");
$blah = fread($fp, filesize($filename));
$write = fputs($fp, '<b>' . $nm . ' </b> (' . $REMOTE_ADDR . ')<br>' . $co . '<br><br>' . $blah);
fclose($fp);
?>
<meta http-equiv="refresh" content="0">
<?
}
?>
<br><br><br>Comments:<br><br>
<?
$filename = 'talk.txt';
$fp = fopen($filename, "r+");
echo fread($fp, filesize($filename));
fclose($fp);
?>
So, someone want to help?
EDIT: Sorry, I clicked submit twice, somebody delete ONE of the threads.