PHP留言板.docx

上传人:b****8 文档编号:23826591 上传时间:2023-05-21 格式:DOCX 页数:32 大小:24.03KB
下载 相关 举报
PHP留言板.docx_第1页
第1页 / 共32页
PHP留言板.docx_第2页
第2页 / 共32页
PHP留言板.docx_第3页
第3页 / 共32页
PHP留言板.docx_第4页
第4页 / 共32页
PHP留言板.docx_第5页
第5页 / 共32页
点击查看更多>>
下载资源
资源描述

PHP留言板.docx

《PHP留言板.docx》由会员分享,可在线阅读,更多相关《PHP留言板.docx(32页珍藏版)》请在冰豆网上搜索。

PHP留言板.docx

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."\n";

$fp=fopen($guestfile,"a");

fputs($fp,$guestcontent);

fclose($fp);

}

}

?

>

zihanonlinegbook

 

include('head.htm');?

>

if($errorm)

{

echo"";

echo"";

echo"$errorm";

echo"";

echo"";

}

?

>

姓名(必填)

主页:

//">

来自:

Email:

请留言(必填)

   

管理密码:

 

请输入关键字:

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,"$keyword",$content[$i]);

$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"下面的留言中包含关键字$keyword共".$count."条

";

}

?

>

共有

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.">删除 第$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"出错了,$errorm";

echo"";

echo"";

}

?

>

留言大名

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 节日庆典

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1