仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 828|回复: 19
打印 上一主题 下一主题

[学习教程] PHP网页编程之一个php作的文本留言本的例子(一)

[复制链接]
因胸联盟 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-4 00:06:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
在一个团队之中或者说是在一个公司的工作岗位上,需要注重团队之间的交流合作;在学习或工作上都要端正自己的态度,要以认真的态度来对每件事,这样才能让自己更快的投入、更快的学习,而不至于浪费自己的时间。   人人晓得,数据库关于收集来讲的主要性.因为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>
------------------
未完待续...
我是根据自己的成长历程来写的,如有不对的还请指正。
若天明 该用户已被删除
沙发
发表于 2015-2-4 08:54:24 | 只看该作者
多看优秀程序员编写的代码,仔细理解他们解决问题的方法,对自身有很大的帮助。
愤怒的大鸟 该用户已被删除
板凳
发表于 2015-2-5 20:22:27 | 只看该作者
先学习php和mysql,还有css(html语言很简单)我认为现在的效果比以前的方法好。
灵魂腐蚀 该用户已被删除
地板
发表于 2015-2-7 06:10:50 | 只看该作者
多看优秀程序员编写的代码,仔细理解他们解决问题的方法,对自身有很大的帮助。
分手快乐 该用户已被删除
5#
发表于 2015-2-20 17:04:59 | 只看该作者
当然这种网站的会员费就几十块钱。
蒙在股里 该用户已被删除
6#
发表于 2015-2-22 20:16:48 | 只看该作者
先学习php和mysql,还有css(html语言很简单)我认为现在的效果比以前的方法好。
因胸联盟 该用户已被删除
7#
 楼主| 发表于 2015-2-24 05:50:32 | 只看该作者
先学习php和mysql,还有css(html语言很简单)我认为现在的效果比以前的方法好。
再见西城 该用户已被删除
8#
发表于 2015-3-2 01:25:53 | 只看该作者
说点我烦的低级错误吧,曾经有次插入mysql的时间 弄了300年结果老报错,其实mysql的时间是有限制的,大概是到203X年  具体的记不清啦,囧。
冷月葬花魂 该用户已被删除
9#
发表于 2015-3-8 17:57:00 | 只看该作者
使用zendstdio 写代码的的时候,把tab 的缩进设置成4个空格是很有必要的
简单生活 该用户已被删除
10#
发表于 2015-3-11 10:54:50 | 只看该作者
写的比较杂,因为我也是个新手,不当至于大家多多指正。
山那边是海 该用户已被删除
11#
发表于 2015-3-17 17:09:51 | 只看该作者
使用 jquery 等js框架的时候,要随时注意浏览器的更新情况,不然很容易发生框架不能使用。
12#
发表于 2015-3-24 12:57:07 | 只看该作者
装在C盘下面可以利用windows的ghost功能可以还原回来(顺便当做是重转啦),当然啦我的编译目录要放在别的盘下,不然自己的劳动成果就悲剧啦。
不帅 该用户已被删除
13#
发表于 2015-3-24 18:45:13 | 只看该作者
你很难利用原理去编写自己的代码。对于php来说,系统的学习我认为还是很重要的,当你有一定理解后,你可你针对某种效果研究,我想那时你不会只是复制代码的水平了。
谁可相欹 该用户已被删除
14#
发表于 2015-3-26 14:18:27 | 只看该作者
写的比较杂,因为我也是个新手,不当至于大家多多指正。
深爱那片海 该用户已被删除
15#
发表于 2015-4-16 11:09:46 | 只看该作者
作为一个合格的coder 编码的规范是必须,命名方面我推崇“驼峰法”,另外就是自己写的代码最好要带注释,不然时间长了,就算是自己的代码估计看起来都费事,更不用说别人拉。
飘飘悠悠 该用户已被删除
16#
发表于 2015-4-24 05:38:22 | 只看该作者
学好程序语言,多些才是王道,写两个小时代码的作用绝对超过看一天书,这个我是深有体会(顺便还能练打字速度)。
再现理想 该用户已被删除
17#
发表于 2015-4-26 23:07:12 | 只看该作者
学好程序语言,多些才是王道,写两个小时代码的作用绝对超过看一天书,这个我是深有体会(顺便还能练打字速度)。
只想知道 该用户已被删除
18#
发表于 2015-4-29 05:54:12 | 只看该作者
在学习的过程中不能怕麻烦,不能有懒惰的思想。学习php首先应该搭建一个lamp环境或者是wamp环境。这是学习php开发的根本。虽然网络上有很多集成的环境,安装很方便,使用起来也很稳定、
莫相离 该用户已被删除
19#
发表于 2015-6-6 10:41:13 | 只看该作者
我学习了一段时间后,我发现效果并不好(估计是我自身的问题)。因为一个人的精力总是有限的,同时学习这么多,会导致每个的学习时间都得不到保证。
小魔女 该用户已被删除
20#
发表于 2015-6-26 20:35:55 | 只看该作者
建议加几个专业的phper的群,当然啦需要说话的人多,一处一点问题能有人回答你的,当然啦要让人回答你的问题,平时就得躲在里面聊天,大家混熟啦,愿意回答你问题的人自然就多啦。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-29 06:45

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表