该站刚成立不久,便有网友给我来信,说:对于支持PHP的免费个人主页空间不支持用户的MySQL,怎么编写留言板?其实留言板的编写还有一种很简单的方法,那就是操作文本文件的方式。
写两个PHP文件(note.php和result.php)另外加一个保存留言记录的文本文件(note.txt)。
好了,先看例子:(note.php)
<html>
<head><title>小小留言本</title></head>
<style type="text/css">
<!--
.{ font-family: "宋体"; font-size: 9pt;color:#000000}
-->
</style>
<body bgcolor=#cccccc>
<center><font style=" color=color:#cccccc;font-size:12pt">小小留言本</font></center>
<form method="POST" action="result.php">
<center>
<table border=0 width=80%>
<tr>
<td width=20%>您的大名:
</td>
<td width=80%><input type=text name=nickname style=width:100%>
</td>
</tr>
<tr>
<td width=20%>电子邮件:
</td>
<td width=80%><input type=text name=email style=width:100%>
</td>
</tr>
<tr>
<td width=20%>留言:
</td>
<td width=80%><textarea name=note style=width:100%></textarea>
</td>
</tr>
<tr>
<td width=20%> </td>
<td width=80% align=center><input type="submit" value="确定"><input type="reset" value="重写">
</td>
</tr>
</table>
<hr>
<?
$f = fopen("note.txt","r");
$msg = fread($f,filesize("note.txt"));
fclose($f);
print "$msg";
?>
<p align=right><font style=" color=color:#cccccc;font-size:12pt">作者:<a href="mailto:greenchn@163.net">东方一蛇</a><br>
主页:<a href="http://bianceng.cn">编程入门</a></font>
</center>
</body>
</html>
写两个PHP文件(note.php和result.php)另外加一个保存留言记录的文本文件(note.txt)。
好了,先看例子:(note.php)
<html>
<head><title>小小留言本</title></head>
<style type="text/css">
<!--
.{ font-family: "宋体"; font-size: 9pt;color:#000000}
-->
</style>
<body bgcolor=#cccccc>
<center><font style=" color=color:#cccccc;font-size:12pt">小小留言本</font></center>
<form method="POST" action="result.php">
<center>
<table border=0 width=80%>
<tr>
<td width=20%>您的大名:
</td>
<td width=80%><input type=text name=nickname style=width:100%>
</td>
</tr>
<tr>
<td width=20%>电子邮件:
</td>
<td width=80%><input type=text name=email style=width:100%>
</td>
</tr>
<tr>
<td width=20%>留言:
</td>
<td width=80%><textarea name=note style=width:100%></textarea>
</td>
</tr>
<tr>
<td width=20%> </td>
<td width=80% align=center><input type="submit" value="确定"><input type="reset" value="重写">
</td>
</tr>
</table>
<hr>
<?
$f = fopen("note.txt","r");
$msg = fread($f,filesize("note.txt"));
fclose($f);
print "$msg";
?>
<p align=right><font style=" color=color:#cccccc;font-size:12pt">作者:<a href="mailto:greenchn@163.net">东方一蛇</a><br>
主页:<a href="http://bianceng.cn">编程入门</a></font>
</center>
</body>
</html>