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

PHP
利用discuz实现PHP大文件上传应用实例代码
php 遍历显示文件夹下所有目录、所有文件的函数,没有分页的代码
php在字符串中查找另一个字符串
php下HTTP Response中的Chunked编码实现方法
PHP实现定时生成HTML网站首页实例代码
PHP下一个非常全面获取图象信息的函数
PHP strtr() 函数使用说明
php 删除无限级目录与文件代码共享
php AJAX实例根据邮编自动完成地址信息
php miniBB中文乱码问题解决方法
cmd下运行php脚本
PHP 遍历XP文件夹下所有文件
php 移除数组重复元素的一点说明
discuz论坛 用户登录 后台程序代码
Optimizer与Debugger兼容性问题的解决方法
Zend Studio 无法启动的问题解决方法
php 页面执行时间计算代码
php smarty的预保留变量总结
php获取网页内容方法总结
php读取msn上的用户信息类

PHP 中的 基于文本的留言簿


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 295 ::
收藏到网摘: 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";
}
}
?>