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

现在我们来讲一下reply.php的代码:
---------------------------------
//reply.php

<?

function check_strlen_long($txt)
{
$len=strlen($txt);
$count=0;
for ($i=0;$i<$len;$i++)
{
if (ord($txt[$i])<128)
  { $count=$count+1;}
  if (ord($txt[$i])==10 or ord($txt[$i])==32)
  {$count=0;}
  if ($count>=60)  
  {
  $txt[$i]="n";
  $count=0;
  }
}
  return $txt;
}

function encode ($txt)
{
$txt=strip_tags($txt);
$txt=htmlspecialchars($txt);
$message=StripSlashes($txt);
return $message;
}

$content=file("guest.txt");
  $disptext=$content[$record-1];

if ($job=="addreply" and $replyname!="" and $replycontent!="")
{
$content=file("guest.txt");
$count=count($content);
$time = date(Y年m月d日H小时i分);
$ip=$REMOTE_ADDR;
$replycontent=StripSlashes($replycontent);
$replyname=encode($replyname);
$replycontent=htmlspecialchars($replycontent);
  $replycontent=check_strlen_long($replycontent);
$replycontent=nl2br($replycontent);
$replycontent=ereg_replace(chr(10),"",$replycontent);
$content[$record-1]=substr($content[$record-1],0,strlen($content[$i])-1); $content[$record-1]=$content[$record-1]."<!--reply><tr><td colspan=4><ul><font color=#AB00E1>回复内容:</font><br>".$replycontent."<br>回复人大名:".$replyname."<br><font color=#CC33FF>时间:$time 来自:$ip</font></ul><hr size=1 color=blue></td></tr>n";
$fp=fopen("guest.txt","w");
for ($i=0;$i<$count;$i++)
  {
   fputs($fp,$content[$i],strlen($content[$i]));
  }
  echo "<meta http-equiv=Refresh content=1;url=guest.php>";
  exit;

}
  ?>  
<title>zihanonline</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: 10p}
TH {FONT-SIZE: 10pt}
TD {FONT-SIZE: 10pt}
-->
</style>
<body bgcolor="#FFFFFF" background="back.gif">
<div align=center >
  <? include('head.htm');?>
  <table border= 1  width= 65%  height= 169 cellpadding="8" cellspacing="0" bordercolor="#E3E3E3" >
    <form method= POST  action=reply.php >
      <?
      if ($Submit)
       {
        if ($replyname=="" or $replycontent=="")
        {
      echo"<tr align=left valign=middle bgcolor=#F0F0F0> ";
      echo"<td width= 100%  height= 31 > ";
      echo "<font color=red>出错了</font>回复人姓名和回复内容必填!";
      echo"</td>";
      echo"</tr>";
       }
       }
      ?>
      <? echo $disptext ?>  
      <tr align="left" valign="middle" bgcolor="#F0F0F0">  
        <td width= 100%  height= 31 bgcolor="#FFFFFF" > 回复大名  
          <input type= text  name= replyname  size= 20 >
        </td>
      </tr>
      <tr valign="middle">  
        <td width= 100%  height= 26  align= left bgcolor="#f0f0f0" >  
          <p>回复内容</p>
          </td>
      </tr>
      <tr align="center">  
        <td width= 100%  height= 52  valign= top bgcolor="#FFFFFF" >  
          <textarea rows= 6  name= replycontent  cols= 46 wrap="VIRTUAL" ></textarea>
        </td>
      </tr>
      <tr valign="middle" align="center" bgcolor="#F0F0F0">  
        <td width= 100%  height= 14 bgcolor="#f0f0f0" >  
          <input type=hidden name=job value=addreply>
          <input type=hidden name=record value=<? echo $record ?>>
          <input type= submit  value= 提交  name=Submit >
               
          <input type=reset value= 重写  name= B2 >
        </td>
      </tr>
    </form>
    </table>   
    <?include('bottom.htm');?>        
</div>
</body>
</html>
------------------
到此为止,php的代码我们已经写完,剩下的是您要作一个留言本的本头和底部
您可以设计任何的样式.不过记得在本头上面要有至少3个连接:查看 返回主页  
发邮件.这样您的留言本系统才算完整.不过由于这是一文本的留言本,所以您不用担心数据库的问题,您只要再写一个guest.txt的文件就完整了.虽然这个留言本没有mysql等等,可是功能仍然不错.而且是完全属于您自己的留言本.好了,下一节我们将为您讲述guest.txt的建立和上传留言本的几个重要步骤.
未完待续...

(0)

相关推荐

  • PHP+MySQL 制作简单的留言本

    留言显示页面:比上一个例子增加了分页和留言回复的功能 主要代码: install/index.php:程序安装页面 复制代码 代码如下: <?php if($_GET["action"]!=1) { ?> <form method="post" action="index.php?action=1"> <table border="1"> <tr> <td>MySQL

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

    大家知道,数据库对于网络来说的重要性.由于cgi的复杂,现在asp和php+mysql已经成为主流.几乎所有的个人网页都要用到留言本,可是申请的留言本很不稳定.这为网上的交流带来了诸多不便.所以,希望拥有自己的留言本的朋友越来越多. 但是,免费的个人主页支持asp和php的很少.笔者现在向您推荐奥索网,(http://www.oso.com.cn)支持php.这样您便有了能够拥有自己留言本的基础.现在,我就通过一个文本留言本的例子来讲述php的简单使用. 首先,我们先确定,留言的几个过程:写留言

  • 简单的PHP留言本实例代码

    config.php 复制代码 代码如下: <?php $conn = @mysql_connect("localhost","root","") or die("数据库连接出错!"); mysql_select_db("gb",$conn); mysql_query("set names 'GBK'"); ?> add.php 复制代码 代码如下: <?php inc

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

    上两节我针对guest.php和edit.php作了讲述.需要注意的是php和html的区别: php通常是-->(1)<? echo("zihanonline");?>             (2)<? php                   echo("zihanonline");                ?>             (3)<script laanguage="php">

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

    上一次我们研究了guest.php文件.具体的问题还要求读者朋友自己深入的去实践,而且需要一些工具书来学习,如果您一点php的知识都没有,笔者奉劝您就不要想下看了,笔者没有太多的时间和篇幅去逐句探究一个php文件的用途和意义.好的,接下来我们来作edit.php这个文件. ----------- //edit.php <?    if ($Submit)    { if ($SavePassword=="on") {setcookie("TxtPassword"

  • php+mysql写的简单留言本实例代码

    guestbook.php:  <head>  <meta http-equiv="Content-Language" c>  <meta http-equiv="Content-Type" c>  <title></title>  <STYLE>A:link {          COLOR: #002878; TEXT-DECORATION: none  }  A:visited {    

  • 我用php+mysql写的留言本

    guestbook.php: <head> <meta http-equiv="Content-Language" content="zh-cn"> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title></title> <STYLE>A:link {    

  • 超级简单的php+mysql留言本源码

    共3个文件 IncDB.php数据库连接 index.php首页 InsetToDB.php数据库操作 数据库lguestbook里面建表 复制代码 代码如下: CREATE TABLE `intd` ( `id` int(11) NOT NULL auto_increment, `name` varchar(255) character set utf8 collate utf8_bin NOT NULL, `text` text character set utf8 collate utf8

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

    这一节我将为大家讲述关于guest.txt的建立方法和上传的有关事项. ------- //guest.txt <tr><td><font color=#AB00E1>留言内容:</font><br><!--content>zihanonline<!--endcontent> <br><font color=#6633FF>留言人大名:</font><!--name>ziha

  • 解析PHP留言本模块主要功能的函数说明(代码可实现)

    一,敏感词处理1,过滤敏感词preg_match()函数用来在字符串中搜索所有与给定的正则表达式匹配的内容,如果存在则返回True,否则返回False.语法:int preg_match(string pattern,string subject[,array matches[,int flags]])preg_match()函数参数说明如下:pattern:必要参数,需要匹配的正则表达式subject:必要参数,输入的字符串matches:可选参数.输出搜索结果的数组,例如$out[0]将包含

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

    这一节我们将dele.php和sys.php放上来. --------- //dele.php<html> <head> <title>删除留言</title> <style> <!-- A:link {text-decoration: none ; color:0000ff} A:visited {text-decoration: none; color:004080} A:active {text-decoration: none} A

  • flash+php+mysql打造简单留言本教程第1/3页

    (主要参考了火山的帖子:★FLASH与ASP通信入门教程--做真正属于自己的留言本!).网上没有比较好的php留言本相关教程,我下载的N多源文件都看得云里雾里,而且好多都将代码写在MC上.又或许可能有好的教程我没搜到,但无论如何,我现在要在这里班门弄斧一番了. flash+php+mysql简单留言本教程 目的: 用flash+php+mysql制作一个简单的留言本. 配置环境: 最开始肯定是先配置相应的环境了.我下载的是配置环境套件包,傻瓜式的方法,简易安装,比较适合我.下载地址:http:/

  • php mysql 留言本应用实例第1/2页

    复制代码 代码如下: <?php $hostname_conn = "localhost"; $database_conn = "test"; $username_conn = "root"; $password_conn = "1981427"; $conn = mysql_connect($hostname_conn, $username_conn, $password_conn); ?> 复制代码 代码如下:

随机推荐