戻る      guest_input.php     

《PHP言語 /guest_input.php》

<html>
<head>
<title>ゲストブック</title>
</head>
<body>
<h1 style="background:#cccccc">ゲストブック(書き込み)</h1>
<form method="POST" action="guest_write.php">
お名前:
<input type="text" name="name" size="20" maxlength="30" /><br />
メッセージ:
<input type="text" name="message" size="70" maxlength="255" /><br />
<input type="submit" value="送信" />
</form>
</body>
</html>



《PHP言語 /guest_write.php》

<?php
$file=fopen("guest.dat","a");
flock($file,LOCK_EX);
$line =date("Y年 m月 d日 H:i:s")."\t";
$line.=$_POST['name']."\t";
$line.=$_POST['message']."\t";
fputs($file,$line."\n");
flock($file,LOCK_UN);
fclose($file);
header("Location: guest_input.php");⇒require_once("guest_input.php");に変更


《PHP言語 /guest_read.php》

<html>
<head>
<title>ゲストブック</title>
</head>
<body>
<h1 style="background:#cccccc">ゲストブック(閲覧)</h1>
<?php
$file=fopen("guest.dat","r");
while($row=fgetcsv($file,1024,"\t")){
?>
<ol>
<li>お名前:<?php print($row[1]); ?></li>
<li>メッセージ:<?php print($row[2]); ?></li>
<li>書き込み日時:<?php print($row[0]); ?></li>
</ol>
<hr />
<?php
}
fclose($file);
?>
</body>
</html>