Weil der Wunsch in einem anderen Thread dahin ging, ein Script zu erstellen, um
Benutzern einer Seite die Möglichkeit zu geben ein Kommentar zu erstellen, habe
ich mir mal die Freiheit genommen eines zu machen.
Das ganze besteht aus 3 Datein: kommentar.php, kommentar.dat, eintragen.php
(Das ganze ginge auch mit 2, aber mir gefällt es so besser).
kommentar.php:
PHP-Code:
<html>
<head> <title>Kommentar Script (c)EvoGT</title> </head>
<body>
[b]Kommentare:[/b]
<?php
$fname="kommentar.dat";
$fp=fopen($fname,"r") or die ("Error");
$line=fgets($fp,1024);
while(!feof($fp)){
print "
";
list($nickname,$geschlecht,$bewertung,$datum,$kommentar)=split("ƒ", $line);
print "<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='51%' id='AutoNumber1' height='73'>
<tr>
<td width='33%' height='54' style='border-right-style: none; border-right-width: medium; border-bottom-style: solid; border-bottom-width: 1'>
[b]<font color='#008000'>$nickname [i]<font size='2'>($geschlecht)</font>[/i]</font>[/b]</td>
<td width='33%' height='54' style='border-left-style: none; border-left-width: medium; border-bottom-style: solid; border-bottom-width: 1'>
Bewertung: $bewertung/10</td>
<td width='34%' height='54' style='border-left-style: none; border-left-width: medium; border-bottom-style: solid; border-bottom-width: 1'>
<p align='right'>[i]<font color='#FF0000'>$datum</font>[/i]</td>
</tr>
<tr>
<td width='101%' colspan='3' height='19'>$kommentar</td>
</tr>
</table>";
print "
";
$line=fgets($fp,1024);
}
fclose($fp);
print "[i]Keine weiteren Kommentare vorhanden.[/i]
";
?>
[b]Kommentar eintragen:[/b]
<form action="eintragen.php" method=get">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="44%" id="AutoNumber1" height="73">
<tr>
<td width="33%" height="54" style="border-right-style: none; border-right-width: medium; border-bottom-style: solid; border-bottom-width: 1">
Nick: <input type="text" name="nickname" size="11" tabindex="1"></td>
<td width="37%" height="54" style="border-right-style: none; border-right-width: medium; border-bottom-style: solid; border-bottom-width: 1">
<p align="left">Geschlecht: <select size="1" name="geschlecht" tabindex="2">
<option selected>männlich</option>
<option>weiblich</option>
</select></td>
<td width="30%" height="54" style="border-left-style: none; border-left-width: medium; border-bottom-style: solid; border-bottom-width: 1">
Bewertung: <select size="1" name="bewertung" tabindex="2">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option selected>10</option>
</select></td>
</tr>
<tr>
<td width="102%" colspan="3" height="19">Dein Kommentar:
<textarea rows="8" name="kommentar" cols="52" tabindex="3"></textarea>
<p align='right'><input type="submit" value="Kommentar eintragen"></p></td>
</tr>
</table>
</form>
</body>
</hmtl>
eintragen.php
PHP-Code:
<html>
<head>
<title>Kommentar Script (c)EvoGT</title>
</head>
<body>
<?php
$kommentar = str_replace("\r\n", "
", $kommentar);
if ($nickname and $kommentar and $geschlecht and $bewertung){
print "Vielen Dank! Ihr Kommentar wurde erfolgreich eingetragen.";
$fname="kommentar.dat";
$fp=fopen($fname,"a") or die ("Error");
$timestamp = time();
$datum = date("d.m.Y",$timestamp);
$uhrzeit = date("H:i",$timestamp);
$datumzeit = $datum." / ".$uhrzeit." Uhr";
fputs($fp,"$nickname ƒ $geschlecht ƒ $bewertung ƒ $datumzeit ƒ $kommentar \n");
fclose($fp);
}
?>
[url="kommentar.php"]Zurück zum Artikel[/url]
</body>
</html>
kommentar.dat
die datei ist einfach nur leer und muss schreib-/lese-und ausführrechte auf dem server haben (CHMOD 777)
Lesezeichen