在我们的会员狗尾草的要求下我更改了,他下载的留言簿程序,发现了很多的问题!现在讲这些问题公开!也许你也正在为这样的程序烦恼!也许这样的更改能够帮助一些朋友!好了废话不说了!^^祝你们好运!
------------
addlevel.php//加入留言
------------
<html>
<body>
<?// addlevel.php
$filename="leavetxt.txt";
if(!file_exists($filename))
{
$msg="time ,ip ,os ,usrname ,region ,oicq ,email ,leave ";
$fp=fopen($filename,"a");
fwrite($fp,$msg."\n"); //注意这里\n.源程序是"n"
fclose($fp);
}
$fp=fopen($filename,"a");
$msg=Today()." ,$REMOTE_ADDR ,$HTTP_USER_AGENT ,$OS ,".str2f($usrname).",".str2f($region).",".str2f($oicq).",".str2f($email).",".str2f($leave);
fwrite($fp, $msg."\n"); //注意这里\n,源程序也写成了"n"
fclose($fp);
?>
留 言 成 功 <a href='viewnote.php'>返回</a>
</body>
</html>
<?
function str2f($str)
{
$str=stripslashes(trim($str));
$str=htmlspecialchars($str);
$str=str_replace(",",",",$str);
$str=str_replace("rn","<BR>",$str);
$str=str_replace("r","<BR>",$str);
$str=str_replace("n","<BR>",$str);
return $str;
}
function Today()
{
$Td=getDate();
$Tdmon=substr("0".$Td["mon"],-2);
$Tdday=substr("0".$Td["mday"],-2);
$TdHou=substr("0".$Td["hours"],-2);
$TdMin=substr("0".$Td["minutes"],-2);
$TdSec=substr("0".$Td["seconds"],-2);
$Tdy=$Td["year"]."-".$Tdmon."-".$Tdday." $TdHou:$TdMin:$TdSec";
return $Tdy;
}
?>
-----------
guestbook.php//留言簿界面
-----------
<html>
<head>
<title>留言本</title>
<style type='text/css'>
td,div,p { font-family: "verdana","new times"; font-size: 9pt }
.input
{ font-family: "verdana","new times"; font-size: 9pt; border: 1 solid black }
.button {
BACKGROUND-COLOR: #666666; color: white; height:22px; BORDER-BOTTOM: black 1px solid; BORDER-LEFT: white 1px solid; BORDER-RIGHT: black 1px solid; BORDER-TOP: white 1px solid; font-family: "verdana","new times"; font-size: 9pt}
.fm
{ width: 500; text-align: right; font-family: "verdana","new times"; font-size: 9pt
}
</style>
<script language='javascript'>
function checkdata()
{
if(fm.usrname.value=='' || fm.leave.value=='')
{
alert("请检查一下你的大名或留言是否填写,这些是必须的!");
return;
}
if(fm.leave.value.length>=700)
{
alert("Sorry,本留言现最大只支持0.7k的留言内容,请精简一下,谢谢!");
return;
}
fm.action='addlevel.php';
fm.submit();
}
function settime()
{
now = new Date();
h="0"+now.getHours();
m="0"+now.getMinutes();
s="0"+now.getSeconds();
if(h>9){h=now.getHours()}
if(m>9){m=now.getMinutes()}
if(s>9){s=now.getSeconds()}
divtime.innerHTML="现在时间是 "+h+":"+m+":"+s;
setTimeout('settime()', 1000)
}
</script>
</head>
<body bgcolor='#efefef' onload='settime()'>
<center>
<div><b style='font-size: 14pt'> <<<<<<<<狗尾草的留言簿>>>>>>>></b></div>
<div style='width: 500; font-size: 8pt' id=divtime align=right></div>
<form name=fm method=post>
<table width='500' border='1' cellspacing='0' cellpadding='0' bgcolor='#efefef' bordercolorlight="#202020" bordercolordark="#FFFFFF" bordercolor="#999999">
<TR>
<td width=100>姓名</td>
<td width=400> <input class=input size=15 name=usrname maxlength=15>
</td>
</TR>
<TR>
<TD>来自
</TD>
<TD>
<INPUT class=input name=region size=20 maxlength=15>
OICQ <input class=input name=oicq size=10 maxlength=10>
</TD>
</TR>
<TR>
<TD>Email:
</TD>
<TD>
<INPUT class=input name=email size=30 maxlength=40>
</TD>
</TR>
<TR>
<TD valign=top>内容</TD>
<TD> <textarea name=leave cols=50 rows=6 class=input></textarea></TD>
</TR>
</table>
<br>
<div><input type=button value='留言' class=button onclick='javascript: checkdata()'>
<input type=button value='查看留言' class=button onclick='location.href="viewnote.php"'>
</div>
</form>
<div style='height: 30'> </div>
<div style='height: 25px'>狗尾草的留言板</div>
<div>日期:2000年12月6日</div>
</center>
</body>
</html>
--------
viewnote.php//查看留言
--------
<?
header("Expires: 0");
?>
<html>
<head>
<title>留言浏览</title>
<style type='text/css'>
td,div,p { font-family: "verdana","new times"; font-size: 9pt }
a { font-family: "verdana","new times"; font-size: 9pt; text-decoration: none}
a:link{text-decoration:none;color:#000000}
a:visited{text-decoration:none;color:gray}
a:active{text-decoration:none;color: #000000}
a:hover{text-decoration:underline;color: black}
.input
{ font-family: "verdana"; font-size: 9pt; border: 1 solid black }
.button {
BACKGROUND-COLOR: #666666; color: white; height:22px; BORDER-BOTTOM: black 1px solid; BORDER-LEFT: white 1px solid; BORDER-RIGHT: black 1px solid; BORDER-TOP: white 1px solid; font-family: "verdana"; font-size: 9pt}
</style>
<script language='javascript'>
function Query()
{
var tmp=trim(queryfrm.Rcstart.value);
if(!isNum(tmp))
{
alert("请输入数字!");
return;
}
queryfrm.submit();
}
</script>
</head>
<body bgcolor='#efefef'>
<center>
<div style='height: 30'><b><h2>我的留言板</h2></b></div>
<br>
<?
$filename="leavetxt.txt";
if(!file_exists($filename)) { echo "没有留言内容!"; exit;}
$fpcon=file($filename);//返回一个数租$fpcon
//echo $fpcon[0];
//$fpcon=file($filename);
/*********
分页显示
*********/
$RowNum=count($fpcon)-1;//所有的留言数目
//echo "RowNum=".$RowNum;
$pageNum=2;//每页显示的留言数目
$pagetotal=intval(($RowNum-1)/$pageNum)+1;//所有的页数
//echo " pagetotal=".$pagetotal;
$pageNo=intval(($pageNo=='' || $pageNo<=0)?"1":$pageNo);
$pageNo=$pageNo>$pagetotal?$pagetotal:$pageNo; //当前的页数
//echo " pageNo=".$pageNo;
?> <!----分页--->
<div align=center style='border-bottom: 1 solid black; width: 640' >
本留言本每10条信息为一页,现共有 <?=$pagetotal?> 页 目前在第 <?=$pageNo ?> 页
<? if($pageNo==1 ) { ?>
<font color=gray>上一页</font>
<? } else { ?>
<a href='viewnote.php?pageNo=<?=$pageNo-1 ?>'>上一页</a>
<? }
if($pageNo==$pagetotal) { ?>
<font color=gray>下一页</font>
<? } else { ?>
<a href='viewnote.php?pageNo=<?=$pageNo+1 ?>'>下一页</a>
<? } ?> 作者: <a href='mailto:[email protected]'>狗尾草</a>
</div>
<!----分页--->
<div> </div>
<?
$startRow=$RowNum-$pageNo*$pageNum;//关键在这里,源程序写错了!错误的将$startRow写成了$endRow!!!
$endRow=$startRow+$pageNum;
if($startRow<0) $startRow=0;
$i=0;
//echo $startRow;
//echo $endRow;
for($i=$startRow;$i<=$endRow;$i++)
{
$tmp=explode(",",$fpcon[$i]);
//Today().",$REMOTE_ADDR,$HTTP_USER_AGENT,$OS,$usrname,$region,$oicq,".trim
// 1 2 3 4 5 6 7
//($email).str2f($leave);
// 8 9
$ldate=$tmp[0];
$IP=$tmp[1];
$browser=$tmp[2];
$os=$tmp[3];
$usrname=$tmp[4];
$region=$tmp[5];
$oicq=$tmp[6];
$email=trim($tmp[7]);
$leave=$tmp[8];
$rpaly=$tmp[9];
?>
<table width='640' border='1' cellspacing='0' cellpadding='0' bgcolor='<?=($j++%2==0)?"#efefef":"#fefefe"?>' bordercolorlight="#202020" bordercolordark="#FFFFFF" bordercolor="#999999">
<TR>
<TD rowspan=2 align=center width=120>
<div align=left><?=$usrname;?></div>
<br>----<br>
来自<?=$region; ?></TD>
<TD bgcolor='#cccccc' height=18>
<table width=100% height=18 cellspacing=0 cellpadding=0>
<td style='font-size: 8pt' height=18> <?=$usrname;?>留言于:<?=$ldate?></td><td align=right>
<img src="images/ip.gif" alt="<?=$IP?>">
<? if($oicq!='') {?>
<img src="images/oicq.gif" alt="<?=$oicq?>">
<? } ?>
<img src="images/system.gif" alt="<?=$browser?>">
</td>
</table>
</TD>
</TR><TR>
<TD> <?=$leave ?>
<br>
<? if($email!='') {?>
<div align=right><a href='mailto:<?=$email ?>'><img src='images/email.gif' border=0>邮箱</a> </div>
<? } ?>
</TD>
</TR>
</table>
<? } ?>
<div style='height: 30'><b><a href='guestbook.php' style='color: black; font-size: 11pt'><<<<<我
要 留 言>>>>></a></b></div>
<br>
<div style='height: 30'> </div>
<div align=right><a href='http://hunh.oso.com.cn'>回首页>>>>>></a></div>
<div style='height: 25px'>狗尾草 OICQ: 188936</div>
</center>
</body>
</html>
|