一个php作的文本留言本的例子(一)


Posted in PHP onOctober 09, 2006

大家知道,数据库对于网络来说的重要性.由于cgi的复杂,现在asp和php+mysql已经成为主流.几乎所有的个人网页都要用到留言本,可是申请的留言本很不稳定.这为网上的交流带来了诸多不便.所以,希望拥有自己的留言本的朋友越来越多.
但是,免费的个人主页支持asp和php的很少.笔者现在向您推荐奥索网,(http://www.oso.com.cn)支持php.这样您便有了能够拥有自己留言本的基础.现在,我就通过一个文本留言本的例子来讲述php的简单使用.
首先,我们先确定,留言的几个过程:写留言,发送,查看.(搜索)等等.而且对于斑竹来说,管理留言本又是不可或缺的.这样我们就不妨定位于6个php文件,1个文本文件.6个php文件分别为:guest.php manage.php reply.php sys.php del.php edit.php,1个文本文件为:guest.txt
先来看看guest.php的内容,你当然可以直接将下面的内容放到您的php网页里,请尊重作者的劳动,谢谢.
----------------------
//guest.php:<?

require("sys.php");
if ($B1)
{
  if   ($message=="" or $name=="")
  {
  $errorm="<font color=red>出错了!!!</font>姓名和留言内容必填";
  }
  else
{
#写入数据
$space = " ";
$time = date(Y年m月d日H小时i分);
$ip=$REMOTE_ADDR;
$name=encode($name);
$homepage=encode($homepage);
$from=encode($from);
$email=encode($email);
$message=StripSlashes($message);
$message=htmlspecialchars($message);
$message=check_strlen_long($message);
$message=nl2br($message);
$guestcontent = "<tr><td><font color=#AB00E1>留言内容:</font><br><!--content>$message<!--endcontent> ";
$guestcontent=$guestcontent."<br><font color=#6633FF>留言人大名:</font><!--name>$name<!--endname> ";
if ($email !="")
{$guestcontent=$guestcontent."<br><font color=#9900CC>电子信箱</font><a href=\"mailto:$email\"><!--email>$email<!--endemail></a>"."$space";}
if ($homepage !="http://")
{$guestcontent=$guestcontent."<font color=#9900CC>主页:</font>$hompage<a href=\"$homepage\"><!--homepage>$homepage<!--endhomepage></a>";}
$guestcontent=$guestcontent."<br><font color=#0000FF>时间:$time 来自:<!--from>$from<!--endfrom> $ip</font>";
$guestcontent=ereg_replace(chr(10),"",$guestcontent);
$guestcontent=$guestcontent."<hr size=1></td></tr>\n";
$fp=fopen($guestfile,"a");
fputs($fp,$guestcontent);
fclose($fp);
}
}

?>

<html>
<head>
<title>zihanonlinegbook</title>
<style>
<!--
A:link {text-decoration: none ; color:0000ff}
A:visited {text-decoration: none; color:004080}
A:active {text-decoration: none}
A:hover {text-decoration: underline; color:ff0000}
BODY {FONT-SIZE:10pt}
TH {FONT-SIZE:10 pt}
TD {FONT-SIZE: 10pt}
TEXTAREA
{
FONT-FAMILY: "宋体";
FONT-SIZE: 10pt;
}

-->
</style>
<body bgcolor=#FFFFFD background="bg.jpg">
<div align="center">   
  <? include('head.htm');?>
  <table width="68%" border="1" cellpadding="3" cellspacing="0" bordercolor="#E3E3E3">
    <form method="POST" action="guest.php">
      <?
      if ($errorm)
      {
      echo "<tr>";
      echo "<td colspan=3 height=32> ";
      echo "$errorm";
      echo "</td>";
      echo "</tr>";
      }
      ?>  
      <tr>  
        <td width="22%" bgcolor="#F0F0F0"><font color="#000000">姓名<font color="#FF0033">(必填)</font></font></td>
        <td colspan="2" width="78%" bgcolor="#F0F0F0"><font color="#00FF00">  
          <input type="text" name="name" size="40">
          </font></td>
      </tr>
      <tr>  
        <td width="22%" height="29">主页:</td>
        <td colspan="2" height="29" width="78%">  
          <input type="text" name="homepage" size="40" value="http://">
        </td>
      </tr>
      <tr>  
        <td width="22%" height="27" bgcolor="#F0F0F0">来自:</td>
        <td colspan="2" height="27" width="78%" bgcolor="#F0F0F0">  
          <input type="text" name="from" size="40">
        </td>
      </tr>
      <tr>  
        <td width="22%" height="20">Email:</td>
        <td colspan="2" height="20" width="78%"><font color="#00FF00">  
          <input type="text" name="email" size="40">
          </font></td>
      </tr>
      <tr>  
        <td colspan="3" valign="middle" align="left">  
          <div align="center"><font color="#000000">请留言</font><font color="#FF0033">(必填)</font><font color="#00FF00"><br>
            <textarea rows="6" name="message" cols="55" wrap="VIRTUAL"></textarea>
            </font></div>
        </td>
      </tr>
      <tr bgcolor="#F0F0F0">  
        <td colspan="3" height="24">  
          <div align="center"><font color="#00FF00">  
            <input type="submit" value="发  送" name="B1">
                 
            <input type="reset" value="重 写" name="B2">
            </font></div>
        </td>
      </tr>
    </form>
  </table>
  <table width="68%" border="1" cellpadding="4" cellspacing="0" bordercolor="#E3E3E3">
    <tr>  
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
         <form action=manage.php method=post>
          <tr>  
            <td colspan="2">  
              <input type=hidden name=dispflag value=show>
              管理密码:  
              <input  type=password name=password size=8>
                 
              <input type=submit value="确  定" name="submit">
            </td>
          </tr>
          </form>
        </table>
      </td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <form action=guest.php method=post>
          <tr>  
            <td> 请输入关键字:  
              <input type="text" name="keyword" size="10">
              <input type="submit" name="search" value="搜索留言">
            </td>
          </tr>
          </form>
        </table>
      </td>
    </tr>
  </table>
  <?
  function search($keyword)
  {
  global $content;
  $count=count($content);
  $subscript=0;
  $ArrSearch=array();
  for ($i=0;$i<$count;$i++)
   {
   if (ereg($keyword,$content[$i]))  
     {
     $ArrSearch[$subscript]=ereg_replace($keyword,"<font color=red>$keyword</font>",$content[$i]);
     $subscript++;
     }
   }
  return $ArrSearch;
  }//end function
  $one_page_line=15;
  $content = file($guestfile);
  if (isset($search) and isset($keyword) and $keyword!="")
  {
  $content=search($keyword);
  }
  $count =count($content);
  ?>
  <table width="68%" border="0">
    <tr>
      <td>

      <?
      $int_page_count=$count;//总条数;
      $int_page_num=ceil($int_page_count/$one_page_line);//总页数;
      echo "<font color=#CC33FF>分页:";
      for ($i=1;$i<=$int_page_num;$i++)
      {
      echo "<a href=guest.php?page=$i>".$i."</a> ";
      }
     echo "</font>";
     if (isset($search) and isset($keyword) and $keyword!="")
     {
      echo "<br><center>";
      echo "下面的留言中包含关键字<font color=red>$keyword</font>共<font color=red>".$count."</font>条</center>";
     }
      ?>
      </td><td><p align=right>共有<font color=red><?echo "$count"?></font>条</p></td>
    </tr>
  </table>
</div>
  <br>
<table width="68%" border="0" align="center">
<?
      if ($page=="" or !isset($page))
      {$page=1;}
      $text="";
      $begin_line=$int_page_count-($page-1)*$one_page_line;
      if ($begin_line<$one_page_line){$one_page_line=$begin_line;}
      for ($j=$begin_line;$j>($begin_line-$one_page_line);$j--)
      {
          $text=$text."<tr><td align=right colspan=2><a href=reply.php?job=reply&record=".$j.">回复</a> <a href=edit.php?record=".$j.">编辑</a> <a href=dele.php?record=".$j.">删除</a> 第<font color=red>$j</font>条</td></tr>";
          $text.=$content[$j-1];

          //数组找下标从0开始.
         }

echo "$text";
?>
</table>
<?
include('bottom.htm');
?>
</body>  
</html>
------------------
未完待续...

PHP 相关文章推荐
xml+php动态载入与分页
Oct 09 PHP
linux iconv方法的使用
Oct 01 PHP
php中大括号作用介绍
Mar 22 PHP
浅谈php安全性需要注意的几点事项
Jul 17 PHP
php截取中文字符串函数实例
Feb 23 PHP
php给图片添加文字水印方法汇总
Aug 27 PHP
10个php函数实用却不常见
Oct 13 PHP
PHP读取大文件的多种方法介绍
Apr 04 PHP
浅谈PHP错误类型及屏蔽方法
May 27 PHP
PHP编程实现微信企业向用户付款的方法示例
Jul 26 PHP
PHP架构及原理知识点详解
Dec 22 PHP
关于PHP数组迭代器的使用方法实例
Nov 17 PHP
PHP的类 功能齐全的发送邮件类
Oct 09 #PHP
以文本方式上传二进制文件的PHP程序
Oct 09 #PHP
用户的详细注册和判断
Oct 09 #PHP
PHP编程与应用
Oct 09 #PHP
谈谈PHP语法(2)
Oct 09 #PHP
无数据库的详细域名查询程序PHP版(1)
Oct 09 #PHP
无数据库的详细域名查询程序PHP版(2)
Oct 09 #PHP
You might like
PHP 服务器配置(使用Apache及IIS两种方法)
2009/06/01 PHP
ThinkPHP整合百度Ueditor图文教程
2014/10/21 PHP
php提取字符串中网站url地址的方法
2014/12/03 PHP
php中实现xml与mysql数据相互转换的方法
2014/12/25 PHP
CodeIgniter使用smtp服务发送html邮件的方法
2015/06/10 PHP
centos+php+coreseek+sphinx+mysql之一coreseek安装篇
2016/10/25 PHP
用javascript实现画板的代码
2007/09/05 Javascript
基于JavaScript 类的使用详解
2013/05/07 Javascript
Javascript中常见的校验如域名、手机、邮箱等等
2014/01/02 Javascript
三种动态加载js的jquery实例代码另附去除js方法
2014/04/30 Javascript
2014 年最热门的21款JavaScript框架推荐
2014/12/25 Javascript
基于jQuery实现带动画效果超炫酷的弹出对话框(附源码下载)
2016/02/22 Javascript
NodeJS与HTML5相结合实现拖拽多个文件上传到服务器的实现方法
2016/07/26 NodeJs
浅谈react.js 之 批量添加与删除功能
2017/04/17 Javascript
通过一次报错详细谈谈Point事件
2018/05/17 Javascript
vue.js编译时给生成的文件增加版本号
2018/09/17 Javascript
详解vue开发中调用微信jssdk的问题
2019/04/16 Javascript
基于JavaScript 实现拖放功能
2019/09/12 Javascript
js将URL网址转为16进制加密与解密函数
2020/03/04 Javascript
vue项目在webpack2实现移动端字体自适配功能
2020/06/02 Javascript
Python的另外几种语言实现
2015/01/29 Python
Python简单操作sqlite3的方法示例
2017/03/22 Python
安装python3的时候就是输入python3死活没有反应的解决方法
2018/01/24 Python
python顺序的读取文件夹下名称有序的文件方法
2018/07/11 Python
对Django项目中的ORM映射与模糊查询的使用详解
2019/07/18 Python
这可能是最好玩的python GUI入门实例(推荐)
2019/07/19 Python
Python中无限循环需要什么条件
2020/05/27 Python
最新PyCharm 2020.2.3永久激活码(亲测有效)
2020/11/26 Python
深入解析HTML5使用SVG图像时的viewBox属性用法
2015/09/02 HTML / CSS
日本无添加化妆品:HABA
2016/08/18 全球购物
Urban Outfitters德国官网:美国跨国生活方式零售公司
2018/05/21 全球购物
智乐游戏测试笔试题
2014/05/21 面试题
《会变的花树叶》教学反思
2014/02/10 职场文书
2014年店长工作总结
2014/11/17 职场文书
求职推荐信范文
2015/03/27 职场文书
优质护理心得体会
2016/01/22 职场文书