文本文件的留言板

 //登陆页面login.php

<html>
<head>
<title>用户登陆</title>
</head>
<body>
<br><B><FONT COLOR="#000F4">用户登陆</FONT></B>
<table width="800" border="1" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all">
<tr><td style="border-right-style: none">
<form action="validate.php" method="POST" style="font-size: 13px">
姓名:<input id="uername" name="name" maxlength=32 size=32></br>
密码:<input type="password" name="pwd" maxlength=32 size=32></br>
<input class="butten"  type="submit" value="提交" name="submit">
<input class="butten" type="reset" value="重置" name="reset">
<a href=postpage.php>注册用户</a>
</form>
</table>
</body>
</html>

//验证页面validata.php

<?php
if ($_POST['name']=="" or $_POST['pwd']=="") {
  die( "对不起用户密码不能为空!!<a href=login.php>Refresh</a>");
}
if ($_POST['name']==="&") {
  die("对不起,非法字符,请重新输入!!<a href=login.php>Refresh</a>");
 }
$fname=$_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.newfile.DIRECTORY_SEPARATOR."postpage.txt";
//if(!empty($_POST['name'])){
 $usename=strip_tags($_POST['name']);//得到name
 $pwd=strip_tags($_POST['pwd']);//得到pwd
 if (file_exists($fname)) {//判断文件是否存在
 $file=file($fname);//将留言读入数组
 $count=count($file);
 for ($i=0;$i<=$count;$i++){
  list($name,$password,$e_mail,$homepage,$time)=explode("&",$file[$i],5);
  //遍历出结果
  $adddata=$name."&".$password."&".$e_mail."&".$homepage."&".$time."/n";
  if ($usename==$name and $pwd==$password) {
   $host  = $_SERVER['HTTP_HOST'];
         $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '///');
         $extra = 'indextest.php';
         header("Location: http://$host$uri/$extra");//跳转到index.php
         exit();
  }
 }
 die("没有这个用户,请注册!!<a href=postpage.php>Refresh</a>");

}else {
 $fp=fopen($fname,"w");
}
die("没有这个用户,请注册!!<a href=postpage.php>Refresh</a>");
//}
?>

//注册页面postpage.php

<html>
<head>
<title>php爱好者 留言板_提交信息</title>

 <script language="javascript">
function check(){
if(document.form1.name.value == ''){
  alert('昵称不能为空.');
  document.form1.name.select();
  return false;
  }
if(document.form1.email.value != ''){
  var myemail  =   /^[_a-z0-9]+@([_a-z0-9]+/.)+[a-z0-9]{2,3}$/;    
  if(!myemail.test(document.form1.email.value)){  
   alert('Email格式不正确!');
   document.form1.email.select();
   return false;
  }
  }
return true;
}
</script>

</head>
<body>
<center>
<form id="form1" name="form1" method="post" action="pagefor.php">
  <table width="800" border="1" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all">
    <tr>
      <td colspan="4" class="header">签写信息</td>
    </tr>
    <tr>
      <td width="144">昵称(name):<font color="#FF0000">*</font></td>
      <td width="357"><input name="name" type="text" id="name">
    </tr>
    <tr>
      <td width="144">密码:<font color="#FF0000">*</font></td>
      <td width="357"><input name="password" type="password" id="pwd">
    </tr>
    <tr>
      <td>邮箱(email):</td>
      <td><input name="email" type="text" id="email" size="30"></td>
    </tr>
    <tr>
      <td>主页(homepage):</td>
      <td><input name="homepage" type="text" id="homepage" value="http://" size="40"></td>
    </tr>
    <tr>
      <td colspan="4" align="center"><input type="submit" name="Submit" value="提交">
        <input name="Submit2" type="reset" value="重置"></td>
    </tr>
  </table>
</form>
</center>
</body>
</html>

//保存注册信息pagefor.php

<?php
if ($_POST['name']=="" or $_POST['password']=="") {
  die( "对不起用户密码不能为空!!<a href=postpage.php>Refresh</a>");
}
if ($_POST['name']==="&") {
  die("对不起,非法字符,请重新输入!!<a href=postpage.php>Refresh</a>");
 }
 if (!eregi("^[a-z0-9]+@[a-z0-9]+/.+[a-z0-9]{2,3}$",$_POST['email'])) {
  die("您的邮箱不正确,请确认!!<a href=postpage.php>Refresh</a>");
 }
//
 
  $fname=$_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.newfile.DIRECTORY_SEPARATOR."postpage.txt";
  $name=htmlspecialchars(trim($_POST['name']));
  $password=htmlspecialchars(trim($_POST['password']));
  $e_mail=nl2br(htmlspecialchars($_POST['email']));
  $homepage=htmlspecialchars(trim($_POST['homepage']));
  $e_mail=str_replace(" ","&nbsp;",$e_mail);
  $time=date("Y")."年".date("m")."月".date("d")."日[".date("H").":".date("i").":".date("s")."]";
  $adddata=$name."&".$password."&".$e_mail."&".$homepage."&".$time."/n";
  if(file_exists($fname)){
    $filebuffer=file($fname);
    if(sizeof($filebuffer)>100){
      for($i=0;$i<100;$i++)
        $newbuffer[i]=$filebuffer[i];
    }
    else{
      $newbuffer=$filebuffer;
    }
    $fp=fopen($fname,"w");
    fputs($fp,$adddata);
    fclose($fp);
    $buffer=implode("",$newbuffer);
    $fp=fopen($fname,"a");
    fputs($fp,$buffer);
    fclose($fp);

  }
  else{
        $fp=fopen($fname,"w");
        fwrite($fp,$adddata);
        fclose($fp);
  }

echo "<meta http-equiv='refresh' content='0;url=indextest.php'>";
?>

//显示留言index.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>留言板</title>
</head>
<body>

<br><B><FONT COLOR="#000F4">留言板</FONT></B>
<center>
<table width="800" border="1" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all">
<tr><td style="border-right-style: none">
<form method="post" action="indextsave.php" style="font-size: 13px">
 姓名:<br><input type="text" name="guest_name" maxlength=32 size=32><br>
 留言:(字数:<font color="#0000FF"><span id=sNum>0</span></font>/256)<br>
<textarea class="textForm" name="guest_msg" cols="64" rows="8" οnkeyup="sNum.innerHTML=this.value.length"></textarea><br>
<input class="button" type="submit" name="submit" value="发表留言">
<input class="button" type="reset" value="重置" name="reset">
</form>
</td></tr>
</table>
<?php
include("listpagetest.php");
if(!empty($_GET['p'])){
$num=$_GET['p'];
listpage($num);
}else listpage(1);
?>
</center>
</body>
</html>
//分页显示listpage.php

<html>
<body>
<head>
<title>显示留言</title>
</head>
<?php
function listpage($p)
{ ?>
<table width="800" border="0" bordercolor="#88CCEE" cellspacing="0" cellpadding="4">
<tr><td>
<?php
$perPage=6; //每页显示留言数目
$num=$p;
if($num<1) $num=1;
$prev=$num-1; //上一页
$next=$num+1; //下一页
$page=$num-1; //当前页码
$fname=$_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.newfile.DIRECTORY_SEPARATOR."guestpage.txt"; //存储留言的文件
if(file_exists($fname))
$all_msg=file($fname); //将留言读入数组
$line_count=count($all_msg); //留言总数
$page_count=ceil($line_count/$perPage); //总页数
if($prev>0)
echo "<a href=indextest.php?p=$prev>上一页</a>  ";
else
echo "上一页  ";
if($line_count>($next-1)*$perPage)
echo "<a href=indextest.php?p=$next>下一页</a>     ";
else
echo "下一页     ";
echo "当前第 ".$num." 页,共有".$page_count."页,".$line_count."条留言。";
?>
</p></td></tr>
</table>
<table width="800" border="1" bordercolor="#88CCEE" cellpadding="3" cellspacing="0" style="border-collapse:collapse; font-size:12px; word-break:normal; table-layout:fixed;">
<tr height="18" bgcolor="#5FBEF8"><td width="20%">
<b>留言时间/留言者</b></td><td width="86%"><b>留言内容</b>
</td></tr>
<?php
//显示留言
$bg1="#FBF9F9"; $bg2="#E9EFF4";$bg=$bg2;
for($n=$line_count-1-$page*$perPage;$line_count-1-$page*$perPage-$n<$perPage;$n--){
if(!empty($all_msg[$n])){
//list($time,$ip,$name,$msg)=explode("&",$all_msg[$n],4); //获取留言内容
list($name,$msg,$time)=explode("&",$all_msg[$n],3);//遍历出结果
echo "<tr bgcolor=$bg>";
echo "<td width=14%>".$time."<br><b>".$name."</b></td>";
echo "<td width=86%>".$msg."</td>";
echo "</tr>";
}
}
?>

</table>
<table width="800" border="0" bordercolor="#88CCEE" cellspacing="0" cellpadding="4">
<tr><td>
<p style="line-height: 100%; margin-top: 2; margin-bottom: 2" align="left">
<?php
if($prev>0)
echo "<a href=indextest.php?p=$prev>上一页</a>  ";
else
echo "上一页";
if($line_count>($next-1)*$perPage)
echo "<a href=indextest.php?p=$next>下一页</a>";
else
echo "下一页";
echo "当前第 ".$num." 页,共有".$page_count."页,".$line_count."条留言。";
?>
</p></td></tr>
</table>
<?php } ?>
</form>
</body>
</html>
//保存留言信息indextsave.php

<?php
  $MSG_MAX_LEN=512; //留言最大长度
  $fname=$_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.newfile.DIRECTORY_SEPARATOR."guestpage.txt";
 
  $name=htmlspecialchars(trim($_POST['guest_name']));
  $guest_msg=substr($_POST['guest_msg'],0,$MSG_MAX_LEN);
  $guest_msg = str_replace( "/r/n", "/n", $guest_msg);
  $guest_msg = str_replace( "/r", "/n", $guest_msg);
  $guest_msg = str_replace(" ","  ",$guest_msg);
  $guest_msg = str_replace(">",">",$guest_msg);
  $guest_msg = str_replace("<","<",$guest_msg); 
  $guest_msg = str_replace("/'","'",$guest_msg);
  $guest_msg = nl2br(htmlspecialchars($guest_msg));
 
 
  $time=date("Y")."年".date("m")."月".date("d")."日[".date("H").":".date("i").":".date("s")."]";
  $adddata=$name."&".$guest_msg."&".$time."/n";
  if(file_exists($fname)){
    $filebuffer=file($fname);
    if(sizeof($filebuffer)>100){
      for($i=0;$i<100;$i++)
        $newbuffer[i]=$filebuffer[i];
    }
    else{
      $newbuffer=$filebuffer;
    }
    $fp=fopen($fname,"w");
    fputs($fp,$adddata);
    fclose($fp);
    $buffer=implode("",$newbuffer);
    $fp=fopen($fname,"a");
    fputs($fp,$buffer);
    fclose($fp);
  }
  else{
        $fp=fopen($fname,"w");
        fwrite($fp,$adddata);
        fclose($fp);
  }
  echo "<meta http-equiv='refresh' content='0;url=indextest.php'>";
  ?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值