基于文本的留言簿

固然基数据库的留言簿可以作得很漂亮,而且也更好管理。 但是对于那些没有数据库空间的朋友们来说,基于文本的留言簿也完成可以适用于个人站来使用。而且只要我们努力去做同样可以做得很好,甚至可以说丝毫不比基于数据库的留言簿差。在这里我向介绍一个基于文本的留言簿。在下面这个地址你可以看到它的演示:http://bamboo.oso.com.cn/note.htm,它具有以下两个特点:
1. 用不同的颜我显示不同人发表的留言;
2. 每个留言者具有选择小图标的功能。
本留言簿要由以下四个文件组成:记录留言内容的note.txt文件;记录留言文字显示颜色的color.txt文件;这两个文件都可以有notepad来创建。反应留言表单的note.htm文件;最终处理留言信息的note.php文件。以下是它们的源代码:
note.htm:

 1<html>
 2<head>
 3<title>===留言簿===</title>
 4</head>
 5<body>
 6<form action="note.php" method="POST">   
 7      你的大名:<input name="name" size="44" type="text"/><br/>   
 8      你的邮件地址:<input name="email" size="40" type="text"/><br/>   
 9      你的个人主页:<input name="webname" size="40" type="text"/><br/>   
10      你的个人主页地址:<input name="webadd" size="35" type="text"/><br/>   
11      你的留言:<br/>   
12                 
13<textarea cols="50" name="note" rows="2"></textarea>   
14  请选择你喜欢的图标:   
15   <input checked="" name="icon" type="radio" value="1"/>  <img border="0" height="18" src="n1.gif" width="19"/>        
16<input name="icon" type="radio" value="2"/>  <img border="0" height="16" src="n2.gif" width="16"/>     
17<input name="icon" type="radio" value="3"/>  <img border="0" height="16" src="n3.gif" width="16"/>    
18<input name="icon" type="radio" value="4"/>  <img border="0" height="18" src="n4.gif" width="19"/>      
19<input name="icon" type="radio" value="5"/>  <img border="0" height="18" src="n5.gif" width="19"/>      
20<input name="icon" type="radio" value="6"/>   <img border="0" height="18" src="n6.gif" width="19"/>     
21<input name="icon" type="radio" value="7"/>   <img border="0" height="15" src="n7.gif" width="15"/>      
22<input name="icon" type="radio" value="8"/>   <img border="0" height="18" src="n8.gif" width="19"/>     
23   <input name="icon" type="radio" value="9"/>  <img border="0" height="18" src="n9.gif" width="19"/>        
24<input name="icon" type="radio" value="10"/>  <img border="0" height="18" src="n10.gif" width="18"/>    
25<input name="icon" type="radio" value="11"/>  <img border="0" height="18" src="n11.gif" width="18"/>    
26<input name="icon" type="radio" value="12"/>  <img border="0" height="18" src="n12.gif" width="18"/>      
27<input name="icon" type="radio" value="13"/>  <img border="0" height="15" src="n13.gif" width="15"/>       
28<input name="icon" type="radio" value="14"/>   <img border="0" height="18" src="n14.gif" width="18"/>     
29<input name="icon" type="radio" value="15"/>    <img border="0" height="15" src="n15.gif" width="15"/>            
30
31<div align="left">   
32    
33<input name="B1" type="submit" value="发送"/><input name="B2" type="reset" value="重写"/>
34<a href="note.php?primsg=1">查看留言</a><br/>
35</div>
36</form>
37</body>
38</html>

其中:nx.gif是小图标图片,你自己可以更换。
Note.php:

";} else if ($note=="") { print "你总得说点什么吧?否则点发送干什么?不会是点错了吧?想查看留言?? ```
``` "; } else{ if ($email=="") { print "连电子邮件地址也不给留?我如何跟你联系? ```
``` "; } else if ($webname==""||$webadd="") { print "你没有个人主页?如果有还是希望你给我留下的地址,当作是宣传也可以嘛! ```
``` "; } $t = date(Y年m月d日); $note = str_replace ( "<", "<", $note); $note = str_replace ( ">", ">", $note); $note = str_replace ( "\n", " ```
``` ", $note); $f = fopen("color.txt","r+"); $color1=fread($f,filesize("color.txt")); if($color1==0){ $color=ff0000;} else if($color1==1){ $color="0000ff";} else if($color1==2){ $color="00ff00"; } else if($color1==3){ $color="000000"; } if($color1>=3){ $color1=0;} else{ $color1+=1; } fseek($f,0); fputs($f,$color1); fclose($f); for($I=1;$I<=15;$I++){ if($I==$icon){ $pic=$I; } } $str=strval($pic); $strhtml=" ``` ``` "; $add=" ``` ``` "; $main = "$strhtml ```
``` ``` $name    个人主页: $add$webname      ($t)
说:$note
"; $f = fopen("note.txt","a"); fwrite($f,$main); fclose($f); $f = fopen("note.txt","r"); $msg = fread($f,filesize("note.txt")); fclose($f); echo"$msg"; } } ?>
```
Published At
Categories with Web编程
Tagged with
comments powered by Disqus