本程序共用3个文件
index.htm 输入留言的表单页
list.php 查看留言的页面
addguest.php 添加留言
guests目录中存放留言内容(手工创建GUESTS目录,否则程序会出错)
创建count.txt文件于guests目录,初始值为0
mood目录存放"表情"图片,可以自己做几张图片放在里面.
************************** index.htm *************************
<HTML><HEAD><TITLE>留言</TITLE>
<META content="Microsoft FrontPage 4.0" name=GENERATOR>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<SCRIPT>
function ExpandMe(){
if (typeof(parent.frmMain)!="undefined") {
parent.frmMain.rows="45,*"
}
}
// document.onclick = ExpandMe
// ExpandMe()
</SCRIPT>
</HEAD>
<BODY>
<DIV align=center style="width: 669; height: 531">
<FORM action=addguest.php method=post name=frmAnnounce
onsubmit="return chkSubmit()"><INPUT name=boardID type=hidden value=23>
<P align=center><IMG height=20 src="index.files/iannounce.gif"
width=70>
<a href="list.php">查看留言</a></P>
<P align="left"><SPAN class=smallFont><FONT color=red><B>↑</B></FONT></A> <FONT
color=red><STRONG>*</STRONG></FONT>为必填项目<br>
</SPAN><INPUT name=boardname type=hidden
value=数据库探讨><SPAN class=smallFont>姓 名:</SPAN><INPUT class=smallInput
maxLength=50 name=name size=22><FONT color=red><STRONG>*</STRONG></FONT>
<SPAN class=smallFont>性 别:<input type="radio" name="sex" value="先生" checked>男
<input type="radio" name="sex" value="女士">女</SPAN><SPAN class=smallFont><FONT
color=red><STRONG>*</STRONG></FONT><FONT
color=red><STRONG><br>
</STRONG></FONT>
</SPAN><SPAN
class=smallFont>Email:</SPAN><INPUT class=smallInput maxLength=40 name=email
size=56> <BR><SPAN class=smallFont>主 题:</SPAN><INPUT
class=smallInput maxLength=255 name=subject size=56><FONT
color=red><STRONG>*<br>
</STRONG></FONT><SPAN class=smallFont>主 页</SPAN><SPAN class=smallFont>:</SPAN><INPUT
class=smallInput
name=url size=56></P>
<P align="left"><SPAN class=smallFont>表 情:</SPAN><BR><INPUT CHECKED name=emote type=radio
value=25.gif> <IMG alt="" height=20 src="mood/25.gif" width=20> <INPUT
name=emote type=radio value=12.gif> <IMG alt="" height=20 src="mood/12.gif"
width=20> <INPUT name=emote type=radio value=13.gif> <IMG alt="" height=20
src="mood/13.gif" width=20> <INPUT name=emote type=radio value=14.gif> <IMG
alt="" height=20 src="mood/14.gif" width=20> <INPUT name=emote
type=radio value=15.gif> <IMG alt="" height=20 src="mood/15.gif" width=20>
<INPUT name=emote type=radio value=16.gif> <IMG alt="" height=20
src="mood/16.gif" width=20> <INPUT name=emote type=radio value=17.gif> <IMG
alt="" height=20 src="mood/17.gif" width=20><BR><INPUT name=emote
type=radio value=18.gif> <IMG alt="" height=20 src="mood/18.gif" width=20>
<INPUT name=emote type=radio value=19.gif> <IMG alt="" height=20
src="mood/19.gif" width=20> <INPUT name=emote type=radio value=20.gif> <IMG
alt="" height=20 src="mood/20.gif" width=20> <INPUT name=emote
type=radio value=21.gif> <IMG alt="" height=20 src="mood/21.gif" width=20>
<INPUT name=emote type=radio value=22.gif> <IMG alt="" height=20
src="mood/22.gif" width=20> <INPUT name=emote type=radio value=23.gif> <IMG
alt="" height=20 src="mood/23.gif" width=20> <INPUT name=emote
type=radio value=24.gif> <IMG alt="" height=20 src="mood/24.gif"
width=20></P>
<P>
<div align="left">
<TABLE border=0 cellPadding=0 cellSpacing=0 width=450>
<TBODY>
<TR>
<TD width="60%">
<p align="left">内容:</p>
</TD>
<TD align=right width="40%"><INPUT class=buttonface id=submit1 name=submit1 type=submit
value=" 发 送 ">
<INPUT class=buttonface id=reset1 name=reset1 type=reset value=" 清 除 "></TD></TR>
<TR>
<TD width="100%" colspan="2"><TEXTAREA class=smallarea cols=72 name=content
rows=10></TEXTAREA>
</TD>
</TR></TBODY></TABLE>
</div>
<p align="left">
</FORM>
</div>
<p align="center">返回主页</p>
</BODY></HTML>
************************** list.php **************************
<?php
echo "<p align=center><a href=index.htm>添加留言</a></p>";
$fs = fopen("guests/count.txt","r+");
$count = fgets($fs,10);
if (floor($count/5)>=1) $pageall=floor($count/5)+1; else $pageall=1;
$count1 = $count;
fclose($fs);
if (!$pageno || $pageno<=0) $pageno=1;
if ($pageno>$pageall) $pageno=$pageall;
for ($i=1;$i<=($pageno-1)*5;$i++)
{
$count-=1;
if ($count<=0) {$i=($pageno-1)*5;}
}
$j=1;
while ($count>=1 && $j<=5){
if (file_exists("guests/".$count)) {
$fs = fopen("guests/".$count,"r+");
$content = fgets($fs,10000);
echo $content;
$j+=1;}
$count-=1;}
if ($count=0) echo "暂无留言!";
?>
<P><font color=white>_________________________</font><a href=list.php?pageno=1>首页</a> <?php
if ($pageno<=1) echo "<font color=#C0C0C0>上一页</font>";
else {
$pagenoa=$pageno-1;
echo "<a href=list.php?pageno=".$pagenoa.">上一页</a>";}
?>
<?php
if ($pageno>=$pageall) echo "<font color=#C0C0C0>下一页</font>";
else {
$pagenoa=$pageno+1;
echo "<a href=list.php?pageno=".$pagenoa.">下一页</a>";}
?> <a href=list.php?pageno=<?php echo $pageall?>>尾页</a><font
color=white>_________________________</font></p>
<?PHP
//计数器程序代码
$fs = fopen("count","r+");
$hit = fgets($fs,10);
$hit+=1;
rewind($fs);
fwrite($fs,$hit,10);
$hit = number_format($hit);
fclose($fs);
?>
<p align=center>您是第<?php echo $hit?>位来访者!</p>
<hr><p align=center>Designed by YoungWoo</p>
************************** addguest.php ************************
<?php
//利用文本文件记录留言的数量
$fs = fopen("guests/count.txt","r+");
$count = fgets($fs,10);
$count+=1;
while (file_exists("guests/".$count))
{
$count+=1;
}
$guest = fopen("guests/".$count,"w");
//把留言内容格式化
$mycontent = "<table width=550 cellspacing=1 bgcolor=#FFCB7D cellpadding=5>";
$mycontent = $mycontent."<tr><td width=136 bgcolor=#FFF1DD align=right>";
$mycontent = $mycontent."<p align='center'>".$name."(".$sex.") </p>";
$mycontent = $mycontent."<td width=104 bgcolor=#FFF1DD align=center><font color=#bbbbbb><a
href='mailto:".$email."'>信箱</a></font> ";
if ($url="")
{
$mycontent = $mycontent."<font color=#bbbbbb>主页</font></td>";
}
else
{
$mycontent = $mycontent."<a href=".$url."><font color=#bbbbbb>主页</font></td>";
}
$mycontent = $mycontent."<td width=27 bgcolor=#FFF1DD align=right>";
$mycontent = $mycontent."<p align=center><img border=0 src=mood/".$emote."></p></td>";
$mydate = date("Y年m月d日 h:i:s A");
$mycontent = $mycontent."<td width=250 bgcolor=#FFF1DD align=right>".$mydate;
$mycontent = $mycontent."</td></tr><tr><td width=484 colspan=4 bgcolor=#ffffff><blockquote>";
$mycontent = $mycontent."<p align=left>".$content."<br></td></tr></table><br><br>";
//将内容写入文件
fwrite($guest,$mycontent,strlen($mycontent));
rewind($fs);
fwrite($fs,$count,10);
fclose($fs);
fclose($guest);
echo "留言成功,<a href=index.htm>返回主页</a>!";
?>
**************************************************************
此留言簿只是利用PHP简单实现,很多地方还有不足,还有功能上的欠缺,比如版主的管理功能。希望您看后能
|