PHP留言板.docx
- 文档编号:23826591
- 上传时间:2023-05-21
- 格式:DOCX
- 页数:32
- 大小:24.03KB
PHP留言板.docx
《PHP留言板.docx》由会员分享,可在线阅读,更多相关《PHP留言板.docx(32页珍藏版)》请在冰豆网上搜索。
PHP留言板
大家知道,数据库对于网络来说的重要性.由于cgi的复杂,现在asp和php+MySQL已经成为主流.几乎所有的个人网页都要用到留言本,可是申请的留言本很不稳定.这为网上的交流带来了诸多不便.所以,希望拥有自己的留言本的朋友越来越多.
但是,免费的个人主页支持asp和php的很少.笔者现在向您推荐动站指南,()支持php.这样您便有了能够拥有自己留言本的基础.现在,我就通过一个文本留言本的例子来讲述php的简单使用.
首先,我们先确定,留言的几个过程:
写留言,发送,查看.(搜索)等等.而且对于斑竹来说,管理留言本又是不可或缺的.这样我们就不妨定位于6个php文件,1个文本文件.6个php文件分别为:
guest.phpmanage.phpreply.phpsys.phpdel.phpedit.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="
--content>$message
--endcontent>";
$guestcontent=$guestcontent."
--name>$name
--endname>";
if($email!
="")
{$guestcontent=$guestcontent." $email\"> --email>$email --endemail>"."$space";} if($homepage! ="http: //") {$guestcontent=$guestcontent." $hompage --homepage>$homepage --endhomepage>";} $guestcontent=$guestcontent." $time来自: --from>$from --endfrom>$ip"; $guestcontent=ereg_replace(chr(10),"",$guestcontent); $guestcontent=$guestcontent."
$fp=fopen($guestfile,"a");
fputs($fp,$guestcontent);
fclose($fp);
}
}
?
>
--
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:
10pt}
TD{FONT-SIZE:
10pt}
TEXTAREA
{
FONT-FAMILY:
"宋体";
FONT-SIZE:
10pt;
}
-->
include('head.htm');?
>
if($errorm)
{
echo"
echo"
echo"$errorm";
echo"";
echo"
}
?
>
//">
管理密码:
functionsearch($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,"
$subscript++;
}
}
return$ArrSearch;
}//endfunction
$one_page_line=15;
$content=file($guestfile);
if(isset($search)andisset($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" page=$i>".$i." "; } echo""; if(isset($search)andisset($keyword)and$keyword! ="") { echo"
echo"下面的留言中包含关键字
}
?
>
echo"$count"?
>条
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."
job=reply&record=".$j.">回复 record=".$j.">编辑 record=".$j.">删除 第
$text.=$content[$j-1];
//数组找下标从0开始.
}
echo"$text";
?
>
include('bottom.htm');
?
>
上一次我们研究了guest.php文件.具体的问题还要求读者朋友自己深入的去实践,而且需要一些工具书来学习,如果您一点php的知识都没有,笔者奉劝您就不要想下看了,笔者没有太多的时间和篇幅去逐句探究一个php文件的用途和意义.好的,接下来我们来作edit.php这个文件.
-----------
//edit.php
if($Submit)
{
if($SavePassWord=="on")
{setcookie("TxtPassword","$TxtPassword",time()+30*24*3600);}
else
{setcookie("TxtPassword");}
}
?
>
Td{FONT-SIZE:
10pt;}
TEXTAREA
{
FONT-FAMILY:
"宋体";
FONT-SIZE:
10pt;
}
require("sys.php");
functionreadvalue($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;
}
functionsave($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="
--content>$TxtContent
--endcontent>";
$Wcontent=$Wcontent."
--name>$TxtName
--endname>";
if($TxtEmail!
="")
{$Wcontent=$Wcontent." $TxtEmail"> --email>$TxtEmail --endemail>"."$space";} if($TxtHomepage! ="http: //") {$Wcontent=$Wcontent." $TxtHompage --homepage>$TxtHomepage --endhomepage>";} $Wcontent=$Wcontent." $time来自: --from>$TxtFrom --endfrom>".$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('
--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"
exit;
}else{$errorm="留言人姓名和内容必填!
!
";}
}
else{$errorm="密码错误,只有管理员有权修改!
!
";}
}
?
>
include('head.htm');?
>
if($errormand$Submit)
{
echo"
echo"
echo"
echo"";
echo"
}
?
>
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- PHP 留言板
copyright@ 2008-2022 冰点文档网站版权所有
经营许可证编号:鄂ICP备2022015515号-1