<?php
define ("_FILE_", "data.txt");
if (!empty($_POST["name"]) and !empty($_POST["message"])) {
$name = $_POST["name"];
$message= $_POST["message"];
if (file_exists(_FILE_)) {
$text="<b>$name</b>:$message \n";
$content = file_get_contents(_FILE_);
$content .= $text;
file_put_contents(_FILE_, $content);
}
header("location: ".$_SERVER["PHP_SELF"]);
exit;
}
?>
<form action= "<?=$_SERVER["PHP_SELF"]?>" method="post">
Имя:
<input type="text" name="name" /><br/>
Сообщение:<br/>
<textarea name="message"></textarea><br />
<input type="submit" value="Отправить"/>
</form>
<?php
if (is_file(_FILE_)) {
$messages = file(_FILE_);
$messages = array_reverse($messages);
foreach($messages as $val) {
echo $val.'<br />';
}
}
?>
#26 Пробуй по аналогии.
Изменил: Андрей (11.03.2011 / 21:25)