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


Posted in PHP onOctober 09, 2006

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

<?
   if ($Submit)
   {
if ($SavePassword=="on")
{setcookie("TxtPassword","$TxtPassword",time()+30*24*3600);}
else
{setcookie("TxtPassword");}
   }
?>
<html>
<style type=text/css>
Td {FONT-SIZE: 10pt;}
TEXTAREA
{
FONT-FAMILY: "宋体";
FONT-SIZE: 10pt;
}

</style>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>修改留言</title>
<?
require("sys.php");
function readvalue($tags,$tage)
{
global $message,$long,$reply;
$StrStart=strlen(strstr($message,$tags))-strlen($tags);//去除标记后变量所在字串的起始位置.
$StrEnd=strlen(strstr($message,$tage));
$len=$StrStart-$StrEnd;
$StrStart=$long-$StrStart;//起始字符.
$StrString=substr($message,$StrStart,$len);
return $StrString;
}

function save($record)
{
global $TxtContent,$TxtEmail,$TxtHomepage,$TxtEmail,$TxtName,$TxtFrom,$TxtReply,$REMOTE_ADDR,$guestfile;
$content=file($guestfile,"r");
$space = " ";
$time = date(Y年m月d日H小时i分);
$ip=$REMOTE_ADDR;
$TxtReply=StripSlashes($TxtReply);
$TxtContent=StripSlashes($TxtContent);
$TxtContent=htmlspecialchars($TxtContent);
$TxtContent=check_strlen_long($TxtContent);
$TxtContent=nl2br($TxtContent);
$Wcontent = "<tr><td><font color=#AB00E1>留言内容:</font><br><!--content>$TxtContent<!--endcontent> ";
$Wcontent=$Wcontent."<br><font color=#6633FF>留言人大名:</font><!--name>$TxtName<!--endname> ";
if ($TxtEmail !="")
{$Wcontent=$Wcontent."<br><font color=#9900CC>电子信箱</font><a href="mailto:$TxtEmail"><!--email>$TxtEmail<!--endemail></a>"."$space";}
if ($TxtHomepage !="http://")
{$Wcontent=$Wcontent."<font color=#9900CC>主页:</font>$TxtHompage<a href="$TxtHomepage" target=new><!--homepage>$TxtHomepage<!--endhomepage></a>";}
$Wcontent=$Wcontent."<br><font color=#0000FF>时间:$time 来自:<!--from>$TxtFrom<!--endfrom> ".$ip."</font>";
$Wcontent=ereg_replace(chr(10),"",$Wcontent);
$Wcontent=$Wcontent."<hr size=1></td></tr>";
$TxtReply=ereg_replace(chr(10),"",$TxtReply);
$WContent=$Wcontent.$TxtReply."n";
$count=count($content);
$fp=fopen($guestfile,"w");
for ($i=0;$i<$count;$i++)
{
if ($i==$record-1)
  {$content[$i]=$WContent;}
fputs($fp,$content[$i]);
}
fclose($fp);
}

$content=file($guestfile,"r");
$message=$content[$record-1];
$long=strlen($message);
$txtcontent=readvalue('<!--content>','<!--endcontent>');
$txtname=readvalue('<!--name>','<!--endname>');
$txtfrom=readvalue('<!--from>','<!--endfrom>');
$txtemail=readvalue('<!--email>','<!--endemail>');
$txthomepage=readvalue('<!--homepage>','<!--endhomepage>');
$txtcontent=strip_tags($txtcontent);
$tags="<!--reply>";
$txtreply=strstr($message,$tags);
$txtreply=ereg_replace(""",""",$txtreply);
if ($Submit)
  {
  if ($TxtPassword==$managepwd)
  {
  if ($TxtName!="" and $TxtContent!="")
    {
  save($record);
  echo "<meta http-equiv=Refresh content="1;url=guest.php">";
  exit;
    }else {$errorm="留言人姓名和内容必填!!";}
  }
  else {$errorm="密码错误,只有管理员有权修改!!";}
  }
?>
</head>

<body bgcolor="#FFFFFF" background="back.gif">
<? include('head.htm');?>
<div align="center">
  <center>
    <table border="1" width="68%" height="31" cellspacing="0" cellpadding="7" bordercolor="#E3E3E3">
     <form action="edit.php" method=post>
     <?
     if ($errorm and $Submit)
     {
        echo"<tr>";  
        echo"<td height=40 colspan=4>";
        echo"<font color=red>出错了,</font>$errorm";
        echo"</td>";
        echo"</tr>";
     }
     ?>
        <tr>  
          <td width="18%" height="37" bgcolor="#f0f0f0"><font color="#000000">留言大名</font></td>
          <td width="39%" height="37" bgcolor="#FFFFFF">  
            <input type="text" name="TxtName" size="26" value=<?echo "$txtname"?>>
             </td>
          <td width="11%" height="37" bgcolor="#f0f0f0"><font color="#000000">来自</font></td>
          <td width="32%" height="37" bgcolor="#FFFFFF">  
            <input type="text" name="TxtFrom" size="20" value=<?echo "$txtfrom"?>>
          </td>
      </tr>
      <tr>  
          <td width="18%" height="31" bgcolor="#f0f0f0"><font color="#000000">主页地址</font></td>
          <td width="39%" height="31" bgcolor="#FFFFFF">  
            <input type="text" name="TxtHomepage" size="26" value=<?echo "$txthomepage"?>>
          </td>
          <td width="11%" height="31" bgcolor="#f0f0f0"><font color="#000000">Email</font></td>
          <td width="32%" height="31" bgcolor="#FFFFFF">  
            <input type="text" name="TxtEmail" size="20" value=<?echo "$txtemail"?>>
          </td>
      </tr>
        <tr bgcolor="#FFFFFF">  
          <td height="31" colspan="4"><font color="#000000">留言内容</font></td>
      </tr>
        <tr bgcolor="#f0f0f0">  
          <td height="105" colspan="4" valign="middle" align="center">  
            <textarea rows="6" name="TxtContent" cols="50" wrap="VIRTUAL"><? echo "$txtcontent"?>
          </textarea>
        </td>
      </tr>
        <tr bgcolor="#FFFFFF">  
          <td height="40" colspan="4" valign="middle" align="center"> <font color="#000000">修改密码</font>  
            <input type="password" name="TxtPassword" size="10" value=<?echo "$TxtPassword"?>>
            <font color="#000000">是否保存密码</font>  
            <input type="checkbox" name="SavePassword" value="on" checked>
          <input type=hidden name=record value=<? echo "$record"?>>

          <input type="submit" value="我要修改了" name="Submit">
        </td>
      </tr>
      <? echo "$txtreply"?>
       <input type=hidden name=TxtReply value="<? echo "$txtreply" ?>">
      </form>
    </table>
  </center>
</div>
<?include('bottom.htm');?>
</body>

</html>
----------
该注明的地方我已作了诠释.php可以嵌入html代码中,这样写起代码很惬意.
待续...

PHP 相关文章推荐
Php做的端口嗅探器--可以指定网站和端口
Oct 09 PHP
怎样在PHP中通过ADO调用Asscess数据库和COM程序
Oct 09 PHP
PHP中$_SERVER的详细参数与说明
Jul 29 PHP
PHP遍历数组的几种方法
Mar 22 PHP
php中curl、fsocket、file_get_content三个函数的使用比较
May 09 PHP
详解WordPress中给链接添加查询字符串的方法
Dec 18 PHP
PHP开发制作一个简单的活动日程表Calendar
Jun 20 PHP
thinkPHP中钩子的两种配置调用方法详解
Nov 11 PHP
Yii框架弹出框功能示例
Jan 07 PHP
php+redis实现注册、删除、编辑、分页、登录、关注等功能示例
Feb 15 PHP
yii框架结合charjs实现统计30天数据的方法
Apr 04 PHP
php 防护xss,PHP的防御XSS注入的终极解决方案
Apr 01 PHP
一个php作的文本留言本的例子(三)
Oct 09 #PHP
一个php作的文本留言本的例子(四)
Oct 09 #PHP
一个php作的文本留言本的例子(五)
Oct 09 #PHP
一个php作的文本留言本的例子(一)
Oct 09 #PHP
PHP的类 功能齐全的发送邮件类
Oct 09 #PHP
以文本方式上传二进制文件的PHP程序
Oct 09 #PHP
用户的详细注册和判断
Oct 09 #PHP
You might like
利用static实现表格的颜色隔行显示
2006/10/09 PHP
php购物车实现代码
2011/10/10 PHP
色色整理的PHP面试题集锦
2012/03/08 PHP
具有时效性的php加密解密函数代码
2013/06/19 PHP
PHP使用Session遇到的一个Permission denied Notice解决办法
2014/07/30 PHP
php微信公众平台开发类实例
2015/04/01 PHP
Laravel学习教程之request validation的编写
2017/10/25 PHP
jquery中的$(document).ready()与window.onload的区别
2009/11/18 Javascript
jQuery contains过滤器实现精确匹配使用方法
2013/04/12 Javascript
jQuery写fadeTo示例代码
2014/02/21 Javascript
JavaScript中匿名、命名函数的性能测试
2014/09/04 Javascript
JS实现简单的键盘打字的效果
2015/04/24 Javascript
ECMAScript5(ES5)中bind方法使用小结
2015/05/07 Javascript
JavaScript中setMonth()方法的使用详解
2015/06/11 Javascript
对象题目的一个坑 理解Javascript对象
2015/12/22 Javascript
JS之相等操作符详解
2016/09/13 Javascript
Javascript函数中的arguments.callee用法实例分析
2016/09/16 Javascript
JavaScript中使用webuploader实现上传视频功能(demo)
2017/04/10 Javascript
vue中路由验证和相应拦截的使用详解
2017/12/13 Javascript
除Console.log()外更多的Javascript调试命令
2018/01/24 Javascript
详解vue axios用post提交的数据格式
2018/08/07 Javascript
js 获取扫码枪输入数据的方法
2020/06/10 Javascript
js实现弹窗猜数字游戏
2020/11/26 Javascript
python杀死一个线程的方法
2015/09/06 Python
利用python微信库itchat实现微信自动回复功能
2017/05/18 Python
pandas使用get_dummies进行one-hot编码的方法
2018/07/10 Python
selenium+python自动化测试之页面元素定位
2019/01/23 Python
Python grequests模块使用场景及代码实例
2020/08/10 Python
牵手50新加坡:专为黄金岁月的单身人士而设的交友网站
2020/08/16 全球购物
升职自荐信
2013/11/28 职场文书
毕业生自荐书模版
2014/01/04 职场文书
大学活动总结范文
2014/04/29 职场文书
投诉信格式范文
2015/07/02 职场文书
导游词之襄阳古城
2019/09/27 职场文书
pandas取dataframe特定行列的实现方法
2021/05/24 Python
python游戏开发Pygame框架
2022/04/22 Python