基于文本的留言簿
更新時(shí)間:2006年10月09日 00:00:00 作者:
固然基數(shù)據(jù)庫(kù)的留言簿可以作得很漂亮,而且也更好管理。 但是對(duì)于那些沒(méi)有數(shù)據(jù)庫(kù)空間的朋友們來(lái)說(shuō),基于文本的留言簿也完成可以適用于個(gè)人站來(lái)使用。而且只要我們努力去做同樣可以做得很好,甚至可以說(shuō)絲毫不比基于數(shù)據(jù)庫(kù)的留言簿差。在這里我向介紹一個(gè)基于文本的留言簿。在下面這個(gè)地址你可以看到它的演示:http://bamboo.oso.com.cn/note.htm,它具有以下兩個(gè)特點(diǎn):
1. 用不同的顏我顯示不同人發(fā)表的留言;
2. 每個(gè)留言者具有選擇小圖標(biāo)的功能。
本留言簿要由以下四個(gè)文件組成:記錄留言內(nèi)容的note.txt文件;記錄留言文字顯示顏色的color.txt文件;這兩個(gè)文件都可以有notepad來(lái)創(chuàng)建。反應(yīng)留言表單的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>
你的個(gè)人主頁(yè):<input type="text" name="webname" size="40"><br>
你的個(gè)人主頁(yè)地址:<input type="text" name="webadd" size="35"><br>
你的留言:<br>
<textarea rows="2" name="note" cols="50"></textarea>
請(qǐng)選擇你喜歡的圖標(biāo):
<input type="radio" value="1" checked name="icon"> <img border="0" src="n1.gif" width="19" height="18">
<input type="radio" name="icon" value="2"> <img border="0" src="n2.gif" width="16" height="16">
<input type="radio" name="icon" value="3"> <img border="0" src="n3.gif" width="16" height="16">
<input type="radio" name="icon" value="4"> <img border="0" src="n4.gif" width="19" height="18">
<input type="radio" name="icon" value="5"> <img border="0" src="n5.gif" width="19" height="18">
<input type="radio" name="icon" value="6"> <img border="0" src="n6.gif" width="19" height="18">
<input type="radio" name="icon" value="7"> <img border="0" src="n7.gif" width="15" height="15">
<input type="radio" name="icon" value="8"> <img border="0" src="n8.gif" width="19" height="18">
<input type="radio" name="icon" value="9"> <img border="0" src="n9.gif" width="19" height="18">
<input type="radio" name="icon" value="10"> <img border="0" src="n10.gif" width="18" height="18">
<input type="radio" name="icon" value="11"> <img border="0" src="n11.gif" width="18" height="18">
<input type="radio" name="icon" value="12"> <img border="0" src="n12.gif" width="18" height="18">
<input type="radio" name="icon" value="13"> <img border="0" src="n13.gif" width="15" height="15">
<input type="radio" name="icon" value="14"> <img border="0" src="n14.gif" width="18" height="18">
<input type="radio" name="icon" value="15"> <img border="0" src="n15.gif" width="15" height="15">
</div>
<div align="left">
<input type="submit" value="發(fā)送" name="B1"><input type="reset" value="重寫(xiě)" name="B2">
<a href="note.php?primsg=1">查看留言</a><br>
</div>
</form>
</body>
</html>
其中:nx.gif是小圖標(biāo)圖片,你自己可以更換。
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 "你總得說(shuō)點(diǎn)什么吧?否則點(diǎn)發(fā)送干什么?不會(huì)是點(diǎn)錯(cuò)了吧?想查看留言??<br>";
}
else{
if ($email=="") {
print "連電子郵件地址也不給留?我如何跟你聯(lián)系?<br>";
}
else if ($webname==""||$webadd="") {
print "你沒(méi)有個(gè)人主頁(yè)?如果有還是希望你給我留下的地址,當(dāng)作是宣傳也可以嘛!<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='n".$str.".gif'>";
$add="<a href=".$webadd."></a>";
$main = "$strhtml<br><font color=$color><a href=\"mailto:$email\">$name</a>    個(gè)人主頁(yè): $add$webname</a>      ($t)<br>
說(shuō):$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";
}
}
?>
1. 用不同的顏我顯示不同人發(fā)表的留言;
2. 每個(gè)留言者具有選擇小圖標(biāo)的功能。
本留言簿要由以下四個(gè)文件組成:記錄留言內(nèi)容的note.txt文件;記錄留言文字顯示顏色的color.txt文件;這兩個(gè)文件都可以有notepad來(lái)創(chuàng)建。反應(yīng)留言表單的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>
你的個(gè)人主頁(yè):<input type="text" name="webname" size="40"><br>
你的個(gè)人主頁(yè)地址:<input type="text" name="webadd" size="35"><br>
你的留言:<br>
<textarea rows="2" name="note" cols="50"></textarea>
請(qǐng)選擇你喜歡的圖標(biāo):
<input type="radio" value="1" checked name="icon"> <img border="0" src="n1.gif" width="19" height="18">
<input type="radio" name="icon" value="2"> <img border="0" src="n2.gif" width="16" height="16">
<input type="radio" name="icon" value="3"> <img border="0" src="n3.gif" width="16" height="16">
<input type="radio" name="icon" value="4"> <img border="0" src="n4.gif" width="19" height="18">
<input type="radio" name="icon" value="5"> <img border="0" src="n5.gif" width="19" height="18">
<input type="radio" name="icon" value="6"> <img border="0" src="n6.gif" width="19" height="18">
<input type="radio" name="icon" value="7"> <img border="0" src="n7.gif" width="15" height="15">
<input type="radio" name="icon" value="8"> <img border="0" src="n8.gif" width="19" height="18">
<input type="radio" name="icon" value="9"> <img border="0" src="n9.gif" width="19" height="18">
<input type="radio" name="icon" value="10"> <img border="0" src="n10.gif" width="18" height="18">
<input type="radio" name="icon" value="11"> <img border="0" src="n11.gif" width="18" height="18">
<input type="radio" name="icon" value="12"> <img border="0" src="n12.gif" width="18" height="18">
<input type="radio" name="icon" value="13"> <img border="0" src="n13.gif" width="15" height="15">
<input type="radio" name="icon" value="14"> <img border="0" src="n14.gif" width="18" height="18">
<input type="radio" name="icon" value="15"> <img border="0" src="n15.gif" width="15" height="15">
</div>
<div align="left">
<input type="submit" value="發(fā)送" name="B1"><input type="reset" value="重寫(xiě)" name="B2">
<a href="note.php?primsg=1">查看留言</a><br>
</div>
</form>
</body>
</html>
其中:nx.gif是小圖標(biāo)圖片,你自己可以更換。
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 "你總得說(shuō)點(diǎn)什么吧?否則點(diǎn)發(fā)送干什么?不會(huì)是點(diǎn)錯(cuò)了吧?想查看留言??<br>";
}
else{
if ($email=="") {
print "連電子郵件地址也不給留?我如何跟你聯(lián)系?<br>";
}
else if ($webname==""||$webadd="") {
print "你沒(méi)有個(gè)人主頁(yè)?如果有還是希望你給我留下的地址,當(dāng)作是宣傳也可以嘛!<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='n".$str.".gif'>";
$add="<a href=".$webadd."></a>";
$main = "$strhtml<br><font color=$color><a href=\"mailto:$email\">$name</a>    個(gè)人主頁(yè): $add$webname</a>      ($t)<br>
說(shuō):$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";
}
}
?>
相關(guān)文章
3種平臺(tái)下安裝php4經(jīng)驗(yàn)點(diǎn)滴
3種平臺(tái)下安裝php4經(jīng)驗(yàn)點(diǎn)滴...2006-10-10Classes and Objects in PHP5-面向?qū)ο缶幊?[1]
Classes and Objects in PHP5-面向?qū)ο缶幊?[1]...2006-10-10php面向?qū)ο笕ヂ?(十) final static const關(guān)鍵字的使用
這個(gè)關(guān)鍵字只能用來(lái)定義類(lèi)和定義方法,不能使用final 這個(gè)關(guān)鍵字來(lái)定義成員屬性,因?yàn)閒inal 是常量的意思,我們?cè)赑HP 里定義常量使用的是define()函數(shù),所以不能使用final 來(lái)定義成員屬性。2009-09-09PHP數(shù)組中頭部和尾部添加元素的方法(array_unshift,array_push)
對(duì)于數(shù)字索引數(shù)組來(lái)說(shuō),通過(guò) array_push()函數(shù)向數(shù)組中尾部添加元素,array_unshift頭部添加元素,需要的朋友可以參考下2017-04-04