当前位置: 首页 > 图文教程 > 网络编程 > PHP > 基于文本的留言簿

PHP
《PHP设计模式介绍》第十三章 适配器模式
《PHP设计模式介绍》第十四章 动态记录模式
《PHP设计模式介绍》第十五章 表数据网关模式
《PHP设计模式介绍》第十六章 数据映射模式
《PHP设计模式介绍》第十七章 MVC 模式
Zend Framework 入门——快速上手
Zend Framework 入门——多国语言支持
Zend Framework 入门——错误处理
Zend Framework 入门——页面布局
详细介绍php5编程中的异常处理
PHP5 OOP编程中的代理与异常
PHP程序的常见漏洞攻击分析
PHP.MVC的模板标签系统
PHP教程:PHP编码书写规范
PHP开发大型项目的方法:OOP思想
php使用curl模拟用户登陆
php对gb编码动态转utf-8编码的几种方法评测
php设计模式介绍之章代理模式
“在phpMyAdmin使用用户口令登陆”补充
PHP入门速成

PHP 中的 基于文本的留言簿


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 106 ::
收藏到网摘: n/a

固然基数据库的留言簿可以作得很漂亮,而且也更好管理。 但是对于那些没有数据库空间的朋友们来说,基于文本的留言簿也完成可以适用于个人站来使用。而且只要我们努力去做同样可以做得很好,甚至可以说丝毫不比基于数据库的留言簿差。在这里我向介绍一个基于文本的留言簿。在下面这个地址你可以看到它的演示:http://bamboo.oso.com.cn/note.htm,它具有以下两个特点:
1. 用不同的颜我显示不同人发表的留言;
2. 每个留言者具有选择小图标的功能。
本留言簿要由以下四个文件组成:记录留言内容的/upload/tech/20091012/20091012013214_5f0f5e5f33945135b874349cfbed4fb9.txt文件;记录留言文字显示颜色的/upload/tech/20091012/20091012013215_093f65e080a295f8076b1c5722a46aa2.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="/upload/tech/20091012/20091012013159_e1e32e235eee1f970470a3a6658dfdd5.gif" width="19" height="18">
<input type="radio" name="icon" value="2"> <img border="0" src="/upload/tech/20091012/20091012013200_04ecb1fa28506ccb6f72b12c0245ddbc.gif" width="16" height="16">
<input type="radio" name="icon" value="3"> <img border="0" src="/upload/tech/20091012/20091012013200_a5e00132373a7031000fd987a3c9f87b.gif" width="16" height="16">
<input type="radio" name="icon" value="4"> <img border="0" src="/upload/tech/20091012/20091012013200_3ad7c2ebb96fcba7cda0cf54a2e802f5.gif" width="19" height="18">
<input type="radio" name="icon" value="5"> <img border="0" src="/upload/tech/20091012/20091012013201_11b921ef080f7736089c757404650e40.gif" width="19" height="18">
<input type="radio" name="icon" value="6"> <img border="0" src="/upload/tech/20091012/20091012013201_d554f7bb7be44a7267068a7df88ddd20.gif" width="19" height="18">
<input type="radio" name="icon" value="7"> <img border="0" src="/upload/tech/20091012/20091012013204_6f3ef77ac0e3619e98159e9b6febf557.gif" width="15" height="15">
<input type="radio" name="icon" value="8"> <img border="0" src="/upload/tech/20091012/20091012013205_5fd0b37cd7dbbb00f97ba6ce92bf5add.gif" width="19" height="18">
<input type="radio" name="icon" value="9"> <img border="0" src="/upload/tech/20091012/20091012013205_85d8ce590ad8981ca2c8286f79f59954.gif" width="19" height="18">
<input type="radio" name="icon" value="10"> <img border="0" src="/upload/tech/20091012/20091012013205_e4da3b7fbbce2345d7772b0674a318d5.gif" width="18" height="18">
<input type="radio" name="icon" value="11"> <img border="0" src="/upload/tech/20091012/20091012013206_1c1d4df596d01da60385f0bb17a4a9e0.gif" width="18" height="18">
<input type="radio" name="icon" value="12"> <img border="0" src="/upload/tech/20091012/20091012013209_fa14d4fe2f19414de3ebd9f63d5c0169.gif" width="18" height="18">
<input type="radio" name="icon" value="13"> <img border="0" src="/upload/tech/20091012/20091012013210_cfcd208495d565ef66e7dff9f98764da.gif" width="15" height="15">
<input type="radio" name="icon" value="14"> <img border="0" src="/upload/tech/20091012/20091012013210_8c235f89a8143a28a1d6067e959dd858.gif" width="18" height="18">
<input type="radio" name="icon" value="15"> <img border="0" src="/upload/tech/20091012/20091012013214_d14220ee66aeec73c49038385428ec4c.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?primsg=1">查看留言</a><br>
</div>
</form>
</body>
</html>
其中:nx.gif是小图标图片,你自己可以更换。
Note.php:
<?
if($primsg==1){
$f = fopen("/upload/tech/20091012/20091012013214_5f0f5e5f33945135b874349cfbed4fb9.txt","r");
$msg = fread($f,filesize("/upload/tech/20091012/20091012013214_5f0f5e5f33945135b874349cfbed4fb9.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("/upload/tech/20091012/20091012013215_093f65e080a295f8076b1c5722a46aa2.txt","r+");
$color1=fread($f,filesize("/upload/tech/20091012/20091012013215_093f65e080a295f8076b1c5722a46aa2.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>    个人主页: $add$webname</a>      ($t)<br>
说:$note <br>";
$f = fopen("/upload/tech/20091012/20091012013214_5f0f5e5f33945135b874349cfbed4fb9.txt","a");
fwrite($f,$main);
fclose($f);
$f = fopen("/upload/tech/20091012/20091012013214_5f0f5e5f33945135b874349cfbed4fb9.txt","r");
$msg = fread($f,filesize("/upload/tech/20091012/20091012013214_5f0f5e5f33945135b874349cfbed4fb9.txt"));
fclose($f);
echo"$msg";
}
}
?>