durch verändern eines vorgegebenes scripts
ich selber hab kaum ahnung von php
das gästebuch speichert die einträge in einer datei an (zb:guestbook.txt)
nun meine frage:
die einträge werden so ausgegeben dass zuerst das erste (also ältester) ausgegeben wird
wie kann ich das ganze umdrehen.. also so dass zuerst das letzte (also das neueste) ausgegeben wird??
ich hab mir überlegt dass bei neuen beiträgen nicht ans ende der datei gespeichert wird sondern das neue beitrag in guestbook.txt immer ganz oben abgespeichet wird
zweite möglichkeit ist dass bei der ausgabe von unten der datei begonnen wird
und zeile für zeile nach oben die einträge ausgegeben werden
nur weiss ich nicht wie man sowas machen kann
bitte um hilfe...
der queltext:
<?php
// Kopfzeile
echo '<html><head><link rel="stylesheet" href="../div/style.css" type="text/css"></head><body><table border="0" cellspacing="0" cellpadding="0" width="655"><tr><th height="24" width="2" background="../div/h1.gif"></th><th height="24" width="651" background="../div/h2.gif" align="left"> Gästebuch</th> <th height="24" width="2" background="../div/h3.gif"></th></tr>';
$datenbankdatei = 'guestbook.txt';
$mailempfaenger = 'xyz@web.de';
// Ueberpruefung ob die Datenbankdatei vorhanden ist.
if(!file_exists($datenbankdatei))
if(!@touch($datenbankdatei))
die("Fehler: Die Datenbank ist nicht erreichbar.");
if(isset($_POST['button']))
{
// Wenn Formular abgeschickt, dann das ausfuehren (Daten in die Datei eintragen)
if($_POST['name'] == "" || $_POST['eintrag'] == "")
{
echo'<tr><td height="1" width="2" background="../div/d1-1.gif"></td><td height="1" width="651" background="../div/d1-2.gif"></td> <td height="1" width="2" background="../div/d1-3.gif"></td></tr><tr><td width="2" background="../div/d2-1.gif"></td><td width="651" background="../div/d2-2.gif"><table border="0" cellspacing="0" cellpadding="5" width="100%"><tr><td><font color="FF0000">Es fehlen Angaben. Bitte vollständig ausfüllen!</font> <a href="guestbook.php">>> zum Gästebuch zurück</a></td></tr></table></td><td width="2" background="../div/d2-3.gif"></td></tr><tr><td height="1" width="2" background="../div/d3-1.gif"></td><td height="1" width="651" background="../div/d3-2.gif"></td><td height="1" width="2" background="../div/d3-3.gif"></td></tr>';
}
else
{
$eintrag = date('d.m.Y - H:i:s').' || '.$_SERVER["REMOTE_ADDR"].' || '.$_POST['name'].' || '.$_POST['email'].' || '.$_POST['eintrag']."\n";
if(!$file = @fopen($datenbankdatei,"a"))
die("Fehler: Die Datenbank ist nicht erreichbar.");
flock($file,LOCK_EX) or die();
if(!@fwrite($file, $eintrag))
die("Fehler: Die Datenbank ist nicht erreichbar.");
flock($file,LOCK_UN) or die();
fclose($file);
// Ausgabe fuer User
echo'<tr><td height="1" width="2" background="../div/d1-1.gif"></td><td height="1" width="651" background="../div/d1-2.gif"></td> <td height="1" width="2" background="../div/d1-3.gif"></td></tr><tr><td width="2" background="../div/d2-1.gif"></td><td width="651" background="../div/d2-2.gif"><table border="0" cellspacing="0" cellpadding="5" width="100%"><tr><td>Danke für deinen Eintrag.<br>Die Daten wurden erfolgreich aufgenommen. <a href="guestbook.php">>> zum Gästebuch zurück</a></td></tr></table></td><td width="2" background="../div/d2-3.gif"></td></tr><tr><td height="1" width="2" background="../div/d3-1.gif"></td><td height="1" width="651" background="../div/d3-2.gif"></td><td height="1" width="2" background="../div/d3-3.gif"></td></tr>';
// email wird verschickt
@mail($mailempfaenger, "Gästebucheintrag - www.CiiBii.de", "Folgender Eintrag wurde hinterlassen:\n\nName: ".$_POST['name']."\nAbsender: ".$_POST['email']."\nText: ".$_POST['eintrag']."\n\nIP: ".$_SERVER["REMOTE_ADDR"]."\n".date('d.m.Y - H:i:s'), "From: ".$_POST['email']."\r\nX-Mailer: PHP/". phpversion());
}
}
else
{
// Formular fuer neue Eintraege
echo'<tr><td height="1" width="2" background="../div/d1-1.gif"></td><td height="1" width="651" background="../div/d1-2.gif"></td> <td height="1" width="2" background="../div/d1-3.gif"></td></tr><tr><td width="2" background="../div/d2-1.gif"></td><td width="651" background="../div/d2-2.gif"><table border="0" cellspacing="0" cellpadding="5" width="100%"><tr><td>
<b>neuer Eintrag:</b><br><br>
<form method="post" action="'.$_SERVER["PHP_SELF"].'">
<table border="0" cellspacing="0" cellpadding="0">
<tr><td valign="top">Ihr Name:</td><td><input type="text" name="name" style="width:200px"></td></tr>
<tr><td valign="top">eMail:</td><td><input type="text" name="email" style="width:200px"></td></tr>
<tr><td valign="top">Ihr Eintrag:</td><td><textarea name="eintrag" rows="5" style="width:550px"></textarea></td></tr>
<tr><td valign="top"> </td><td><input type="submit" name="button" value="Absenden"></td></tr>
</table>
</form>
</td></tr></table></td><td width="2" background="../div/d2-3.gif"></td></tr><tr><td height="1" width="2" background="../div/d3-1.gif"></td><td height="1" width="651" background="../div/d3-2.gif"></td><td height="1" width="2" background="../div/d3-3.gif"></td></tr>';
// wenn das Formular nicht ausgefuelt wurde, dann nur Eintraege anzeigen
$file= fopen($datenbankdatei, 'r');
while (!feof($file))
{
$zeile = fgets($file, 5000);
$daten = explode(" || ", $zeile);
$datum = $daten[0];
$ip = $daten[1];
$name = $daten[2];
$email = $daten[3];
$eintrag = $daten[4];
if($name != "" || $eintrag != "")
echo'<tr><td height="1" width="2" background="../div/d1-1.gif"></td><td height="1" width="651" background="../div/d1-2.gif"></td> <td height="1" width="2" background="../div/d1-3.gif"></td></tr><tr><td width="2" background="../div/d2-1.gif"></td><td width="651" background="../div/d2-2.gif"><table border="0" cellspacing="0" cellpadding="5" width="100%"><tr><td><b>'.$name.'</b> <a href="mailto:'.$email.'">'.$email.'</a> schrieb am '.$datum.' folgendes:<br><br>'.$eintrag.'</td></tr></table></td><td width="2" background="../div/d2-3.gif"></td></tr><tr><td height="1" width="2" background="../div/d3-1.gif"></td><td height="1" width="651" background="../div/d3-2.gif"></td><td height="1" width="2" background="../div/d3-3.gif"></td></tr>';
}
fclose($file);
}
?>