Scusate non sono molto esperto in questo campo, vorrei sapere per quale motivo questo guestbook ordina i messaggi per nome e non per data. Se qualcuno mi puo' dire dove e' sbagliato lo ringrazio
<?php
$error = false;
function signGuestbook(){
global $name,$comments;
$new_guestbook_entry = urlencode($name).",".urlencode($comments)."\n";
$fp=fopen("guestbook.data",a) or exit;
fwrite($fp,$new_guestbook_entry);
fclose($fp);
$name="";
$comments="";
}
function readGuestbook(){
$fp=fopen("guestbook.data",r) or exit;
$rawdata=fread($fp,filesize("guestbook.data"));
fclose($fp);
if($rawdata == ""){
echo "
<font face=\"sans-serif\">Il Guestbook è vuoto</font></p>";
return;
}
$each_line = explode("\n",$rawdata);
rsort($each_line);
$entries = count($each_line)-1;
echo "
<font face=\"sans-serif\">Ci sono $entries commenti</font></p>";
for ($key = 0; $key < count($each_line)-1; $key++){
$temp = explode(",",$each_line[$key]);
$guestbook[$key]["name"] = $temp[0];
$guestbook[$key]["comments"] = $temp[1];
}
for($key = 0; $key < count($guestbook); $key++){
echo "
<font face=\"sans-serif\">Nome: ";
echo htmlspecialchars(urldecode($guestbook[$key]["name"]));
echo "</a>
Commento: ";
echo htmlspecialchars(urldecode($guestbook[$key]["comments"]));
echo "</font></p>";
}
}
if ($sign_guestbook){
if($name != "" && $comments != ""){
signGuestbook();
}else{
$error = true;
}
}
?>
<?php if($error){ ?>
<p align="center"><font face="sans-serif" color="red">Devi riempire tutti i campi!</font></p>
<?php } ?>
<form name=guestbook method="post" action="guestbook.php">
<div align="center">
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<td valign="top" align="left"><font face="sans-serif">Nome:</font></td>
<td valign="top" align="left"><input type="text" name="name" size="70" value="<?php echo addslashes($name); ?>"></td>
</tr>
<tr>
<td valign="top" align="left"><font face="sans-serif">Commento:</font></td>
<td valign="top" align="left"><textarea rows="5" name="comments" cols="61" wrap=virtual><?php echo htmlspecialchars($comments); ?></textarea></td>
</tr>
<tr>
<td valign="top" align="left"></td>
<td valign="top" align="left"><input type="hidden" name="sign_guestbook" value="true"><input type="submit" value="Invia">
<input type="reset" value="Reset"></td>
</tr>
</table>
</div>
</form>
</p>
<font face="sans-serif" size="3">Leggi i commenti: </font></p>
<hr noshade size="1" color="#000000">
<?php readGuestbook(); ?>