<title>Vieraskirja</title>
<h2 style="border-top: solid thin black;
    color:#000;background-color:#fed">
Vieraskirja
</h2>

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="get">
   Nimi:<br>
  <input type="text" name="nimi"><br>
  Viesti:<br>
  <textarea cols="40" rows="4" name="viesti"></textarea><br>
  <input type="submit" name="painike" value="Lähetä">
</form>

<?php
// vieraskirja-v1.php

define("VIERASKIRJA_FILE""/tmp/vieraskirja.txt");

// Lisätään viesti
if(isset($_GET['painike'])) { 
   if (!
$fp = @fopen(VIERASKIRJA_FILE"a")) {
      echo (
"Tiedoston avaamisessa tapahtui virhe!");
      exit();  
   }
   
//Kirjoitetaan viesti vieraskirjaan
   
fwrite($fp"<em>{$_GET['nimi']}</em> kirjoitti:<br>");
   
fwrite($fpnl2br($_GET['viesti']) . "<br><hr>");
   
fclose($fp);
}
?>
<h3 style="border-top: solid thin black;
color:#000;background-color:#eee">
Vieraskirjan viestit</h3>
<?php @include(VIERASKIRJA_FILE?>