




已阅读5页,还剩15页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
大家知道,数据库对于网络来说的重要性.由于cgi的复杂,现在asp和php+MySQL已经成为主流.几乎所有的个人网页都要用到留言本,可是申请的留言本很不稳定.这为网上的交流带来了诸多不便.所以,希望拥有自己的留言本的朋友越来越多.但是,免费的个人主页支持asp和php的很少.笔者现在向您推荐动站指南,()支持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=出错了!姓名和留言内容必填; 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 = 留言内容:$message ;$guestcontent=$guestcontent.留言人大名:$name ;if ($email !=)$guestcontent=$guestcontent.电子信箱$email.$space;if ($homepage !=http:/)$guestcontent=$guestcontent.主页:$hompage$homepage;$guestcontent=$guestcontent.时间:$time 来自:$from $ip;$guestcontent=ereg_replace(chr(10),$guestcontent);$guestcontent=$guestcontent.n;$fp=fopen($guestfile,a);fputs($fp,$guestcontent);fclose($fp);?zihanonlinegbook ? if ($errorm) echo ; echo ; echo $errorm; echo ; echo ; ? 姓名(必填) 主页: 来自: Email: 请留言(必填) 管理密码: 请输入关键字: ? 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,$keyword,$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); ? ? $int_page_count=$count;/总条数; $int_page_num=ceil($int_page_count/$one_page_line);/总页数; echo 分页:; for ($i=1;$i=$int_page_num;$i+) echo .$i. echo ; if (isset($search) and isset($keyword) and $keyword!=) echo ; echo 下面的留言中包含关键字$keyword共.$count.条; ? 共有条 ? if ($page= or !isset($page) $page=1; $text=; $begin_line=$int_page_count-($page-1)*$one_page_line; if ($begin_line($begin_line-$one_page_line);$j-) $text=$text.回复 编辑 删除 第$j条; $text.=$content$j-1; /数组找下标从0开始. echo $text;? 上一次我们研究了guest.php文件.具体的问题还要求读者朋友自己深入的去实践,而且需要一些工具书来学习,如果您一点php的知识都没有,笔者奉劝您就不要想下看了,笔者没有太多的时间和篇幅去逐句探究一个php文件的用途和意义.好的,接下来我们来作edit.php这个文件.-/edit.phpTd FONT-SIZE: 10pt;TEXTAREAFONT-FAMILY: 宋体;FONT-SIZE: 10pt;修改留言?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 = 留言内容:$TxtContent ;$Wcontent=$Wcontent.留言人大名:$TxtName ;if ($TxtEmail !=)$Wcontent=$Wcontent.电子信箱$TxtEmail.$space;if ($TxtHomepage !=http:/)$Wcontent=$Wcontent.主页:$TxtHompage$TxtHomepage;$Wcontent=$Wcontent.时间:$time 来自:$TxtFrom .$ip.;$Wcontent=ereg_replace(chr(10),$Wcontent);$Wcontent=$Wcontent.;$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(,);$txtname=readvalue(,);$txtfrom=readvalue(,);$txtemail=readvalue(,);$txthomepage=readvalue(,);$txtcontent=strip_tags($txtcontent);$tags=;$txtreply=strstr($message,$tags);$txtreply=ereg_replace(,",$txtreply);if ($Submit) if ($TxtPassword=$managepwd) if ($TxtName!= and $TxtContent!=) save($record); echo ; exit; else $errorm=留言人姓名和内容必填!; else $errorm=密码错误,只有管理员有权修改!; ? ? if ($errorm and $Submit) echo; echo; echo出错了,$errorm; echo; echo; ? 留言大名 input type=text name=TxtName size=26 value= 来自 input type=text name=TxtFrom size=20 value= 主页地址 input type=text name=TxtHomepage size=26 value= Email input type=text name=TxtEmail size=20 value= 留言内容 修改密码 input type=password name=TxtPassword size=10 value= 是否保存密码 input type=hidden name=record value= input type=hidden name=TxtReply value= 上两节我针对guest.php和edit.php作了讲述.需要注意的是php和html的区别:php通常是-(1) (2) (3) echo(zihanonline); (4)等4种方式.不要混淆.下面我们来研究信息管理:manage.php代码.-/manage.php留言管理?include(head.htm);include(sys.php);if ($passWord!=$managepwd and $dispflag) echo ; echo ; echo 密码错误!无法删除留言!; echo 程序将在3秒返回; echo 子汉在线斑竹维护管理。; echo ; echo ; exit; ? 0;$h-) $text=$text.删除第.$h.条留言:nn; $text=$text.$content$h-1; echo $text; ? input type=hidden name=password value= ? if ($submit) if ($password!=$managepwd) echo ; echo ; echo 密码错误!无法删除留言!; echo 程序将在3秒返回; echo 子汉在线斑竹维护管理。; echo ; echo ; exit; if ($password=$managepwd) $guest_content=file($guestfile); $count=count($guest_content); for ($j=1;$j=$count;$j+) $del_rec_num=check.$j; $del_num=$del_rec_num; /echo $del_num:$del_num; $guest_content$del_num-1=; $fp=fopen($guestfile,w); for ($i=0;$i=$count-1;$i+) if ($guest_content$i!=) fputs($fp,$guest_content$i,strlen($guest_content$i); fclose($fp); echo ; echo ; echo 留言已正确删除; echo 程序将在3秒返回; echo 子汉在线斑竹维护管理。; echo ; echo ; exit; ? -这一节我们将dele.php和sys.php放上来. - /dele.php 删除留言 ? require(sys.php); if ($Submit) if ($passWord$managepwd) $errorm=密码错误.无权操作.; else $content=file($guestfile); $message=$content$record-1; $count=count($content); if ($dele=delreply) $replylen=strlen(strstr($message,); $long=strlen($message); $len=$long-$replylen; $message=substr($message,0,$len); else $message=; /writefile $fp=fopen($guestfile,w); for ($i=0;$i$count;$i+) if ($i=($record-1)$content$i=$message; fputs($fp,$content$i,strlen($content$i); /end for fclose($fp); echo ; exit; / end ifSubmit $content=file($guestfile); $message=$content$record-1; $found=ereg(,$message);
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 我的成长故事在挑战中成长记事作文5篇
- 活动策划与志愿服务合作承诺函9篇
- 技术团队成果报告评审流程模板多版本比对
- (正式版)DB15∕T 3253.5-2023 《食品生产加工小作坊生产规范 第5部分:熟面食》
- 初中英语语法从句学习教案
- 地球妈妈的家书800字(8篇)
- 团队建设与团队沟通辅助工具包
- 客户关怀与服务水平监测表模板
- 知识产权保护与法律合规性检查工具
- 农业种植基地土地托管合同
- 金属学第三章
- 人工智能训练师(5级)培训考试复习题库-上(单选题汇总)
- 小学科学-哪杯水热教学课件设计
- 酒店明住宿清单(水单)
- 《中国儿童维生素A、维生素D临床应用专家共识》解读
- 应用技术推广中心 报告1212
- 教学第七章-无机材料的介电性能课件
- 应急值班值守管理制度
- 外国文学史-总课件
- 《中小企业划型标准规定》补充说明
- 房屋租赁信息登记表
评论
0/150
提交评论