固然基數據庫的留言簿可以作得很漂亮,而且也更好管理。 但是對于那些沒有數據庫空間的朋友們來說,基于文本的留言簿也完成可以適用于個人站來使用。而且只要我們努力去做同樣可以做得很好,甚至可以說絲毫不比基于數據庫的留言簿差。在這里我向介紹一個基于文本的留言簿。在下面這個地址你可以看到它的演示:http://bamboo.oso.com.cn/note.htm,它具有以下兩個特點: 1. 用不同的顏我顯示不同人發表的留言; 2. 每個留言者具有選擇小圖標的功能。 本留言簿要由以下四個文件組成:記錄留言內容的note.txt文件;記錄留言文字顯示顏色的color.txt文件;這兩個文件都可以有notepad來創建。反應留言表單的note.htm文件;最終處理留言信息的note.php文件。以下是它們的源代碼: note.htm: <html> <head> <title>===留言簿===</title> </head> <body> <form method="POST" action="note.php"> 你的大名:<input type="text" name="name" size="44"><br> 你的郵件地址:<input type="text" name="email" size="40"><br> 你的個人主頁:<input type="text" name="webname" size="40"><br> 你的個人主頁地址:<input type="text" name="webadd" size="35"><br> 你的留言:<br> <textarea rows="2" name="note" cols="50"></textarea> 請選擇你喜歡的圖標: <input type="radio" value="1" checked name="icon"> <img border="0" src=http://www.okasp.com/techinfo/"n1.gif" width="19" height="18"> <input type="radio" name="icon" value="2"> <img border="0" src=http://www.okasp.com/techinfo/"n2.gif" width="16" height="16"> <input type="radio" name="icon" value="3"> <img border="0" src=http://www.okasp.com/techinfo/"n3.gif" width="16" height="16"> <input type="radio" name="icon" value="4"> <img border="0" src=http://www.okasp.com/techinfo/"n4.gif" width="19" height="18"> <input type="radio" name="icon" value="5"> <img border="0" src=http://www.okasp.com/techinfo/"n5.gif" width="19" height="18"> <input type="radio" name="icon" value="6"> <img border="0" src=http://www.okasp.com/techinfo/"n6.gif" width="19" height="18"> <input type="radio" name="icon" value="7"> <img border="0" src=http://www.okasp.com/techinfo/"n7.gif" width="15" height="15"> <input type="radio" name="icon" value="8"> <img border="0" src=http://www.okasp.com/techinfo/"n8.gif" width="19" height="18"> <input type="radio" name="icon" value="9"> <img border="0" src=http://www.okasp.com/techinfo/"n9.gif" width="19" height="18"> <input type="radio" name="icon" value="10"> <img border="0" src=http://www.okasp.com/techinfo/"n10.gif" width="18" height="18"> <input type="radio" name="icon" value="11"> <img border="0" src=http://www.okasp.com/techinfo/"n11.gif" width="18" height="18"> <input type="radio" name="icon" value="12"> <img border="0" src=http://www.okasp.com/techinfo/"n12.gif" width="18" height="18"> <input type="radio" name="icon" value="13"> <img border="0" src=http://www.okasp.com/techinfo/"n13.gif" width="15" height="15"> <input type="radio" name="icon" value="14"> <img border="0" src=http://www.okasp.com/techinfo/"n14.gif" width="18" height="18"> <input type="radio" name="icon" value="15"> <img border="0" src=http://www.okasp.com/techinfo/"n15.gif" width="15" height="15"> </div> <div align="left"> <input type="submit" value="發送" name="B1"><input type="reset" value="重寫" name="B2"> <a href=是小圖標圖片,你自己可以更換。 Note.php: <? if($primsg==1){ $f = fopen("note.txt","r"); $msg = fread($f,filesize("note.txt")); fclose($f); print "$msg"; } else{ if ($name=="") { print "你總得給我留下的你的大名吧!否則我如何稱呼你?<br>";} else if ($note=="") { print "你總得說點什么吧?否則點發送干什么?不會是點錯了吧?想查看留言??<br>"; } else{ if ($email=="") { print "連電子郵件地址也不給留?我如何跟你聯系?<br>"; } else if ($webname==""||$webadd="") { print "你沒有個人主頁?如果有還是希望你給我留下的地址,當作是宣傳也可以嘛!<br>"; } $t = date(Y年m月d日); $note = str_replace ( "<", "<", $note); $note = str_replace ( ">", ">", $note); $note = str_replace ( "\n", "<br>", $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="<img src='http://www.okasp.com/techinfo/n".$str.".gif'>"; $add="<a href=".$webadd."></a>"; $main = "$strhtml<br><font color=$color><a href=\"mailto:$email\">$name</a>    個人主頁: $add$webname</a>      ($t)<br> 說:$note <br>"; $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"; } } ?>
|