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

是因为本国MySQL能源相比恐慌,国外的不是太慢,正是不对本国客户开放。由此,在尚未MYSQL的光阴里,大家想做一些便利客人和百科本身站点的业务,那大概比登天还难,为了超脱这种伤痛,niky哭思冥想,拒谏,终于,百二秦关终属楚,三个无需MYSQL数据库辅助的简要留言本就那样出台了,大家权且叫它gbook.php吧,源程序如下:
? if ($message卡塔尔 { $message = ereg_replace( rnrn,nP, $message卡塔尔国;
//去除无效的决定符号 $date = date( l, F j Y, h:i aState of Qatar;
//获取钦命的日猪时间格式 $ip=getenv(REMOTE_ADDR); $message =table
border=0 cellspacing=0 width=640 cellpadding=0 tr td width=25%B$name
/B/td td width=25%$email/td td width=25%写于–$date/td td
width=25%来自$ip/td /tr tr td width=100% colspan=4$subject/td /tr tr td
width=100% colspan=4$massage/td /tr /tablehr ; $fp = fopen
(basename($PHP_SELF) ..comment,a); fwrite ($fp, $message); fclose
($fp); } @readfile(basename(($PHP_SELF ..comment卡塔尔国卡塔尔国卡塔尔国; //读出记录文件内容
? form method=POST p姓名:input type=text name=name size=20
E-mail:input type=text name=email size=24hr主旨:input type=text
name=subject size=55 p您想说的话:brTEXTAREA name=message rows=10
cols=60 wrap=virtual /TEXTAREAB揽胜br INPUT name=submit type=submit
value=发布! input type=reset value=重写?
name=B2/p/form──────────────────────────────────────
下边包车型大巴主次,其原理是:在PHP端首先推断message变量是不是存在,若是荒诞不经,则读文件。读文件使用了readfile函数。至于文件名的领到,这里运用了三个都行的方法来完毕的。为了能越来越好的就学PHP&MySQL,特拿来和大家共享,也期望已经和niky同样愁肠过的网路人能有二个属于自身的留言本,而不是xxx留言本由xxx.com提供.而败兴而返。还等怎样,飞速行动吧!
版权全数,请勿随意转发! Copyright 二零零三nikyAll rights reserved.

世家知道,数据库对于互联网来讲的要害性.由于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.phpState of Qatar; if ($B1State of Qatar {
if($message== or $name==State of Qatar { $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 = trtdfont
color=#AB00E1留言内容:/fontbr!–content$message!–endcontent ;
$guestcontent=$guestcontent.brfont
color=#6633FF留言人大名:/font!–name$name!–endname ; if ($email !=)
{$guestcontent=$guestcontent.brfont color=#9900CC电子信箱/fonta
href=/mailto:$email/!–email$email!–endemail/a.$space;} if ($homepage
!=) {$guestcontent=$guestcontent.font color=#9900CC主页:/font$hompagea
href=/$homepage/!–homepage$homepage!–endhomepage/a;}
$guestcontent=$guestcontent.brfont 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
titlezihanonlinegbook/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; } ?trtd width=22% bgcolor=#F0F0F0font
color=#000000姓名font color=#FF0033(必填)/font/font/td td colspan=2
width=78% bgcolor=#F0F0F0font color=#00FF00input type=text name=name
size=40 /font/td /tr trtd width=22% height=29主页:/td td colspan=2
height=29 width=78%input type=text name=homepage size=40 value= /td /tr
trtd width=22% height=27 bgcolor=#F0F0F0来自:/td td colspan=2 height=27
width=78% bgcolor=#F0F0F0input type=text name=from size=40 /td /tr trtd
width=22% height=20Email:/td td colspan=2 height=20 width=78%font
color=#00FF00input type=text name=email size=40 /font/td /tr trtd
colspan=3 valign=middle align=leftdiv align=centerfont
color=#000000请留言/fontfont color=#FF0033(必填)/fontfont
color=#00FF00br textarea rows=6 name=message cols=55
wrap=VIRTUAL/textarea /font/div /td /tr tr bgcolor=#F0F0F0td colspan=3
height=24div align=centerfont color=#00FF00input 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 trtd table width=100% border=0 cellpadding=0
cellspacing=0 form action=manage.php method=post trtd colspan=2input
type=hidden name=dispflag value=show 管理密码:inputtype=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 trtd 请输加入关贸总协定组织键字:input
type=text name=keyword size=10 input type=submit name=search
value=找出留言 /td /tr /form /table /td /tr /table ? function
search($keywordState of Qatar { global $content; $count=count($content卡塔尔国;
$subscript=0; $ArrSearch=array(卡塔尔(قطر‎; for ($i=0;$i$count;$i++State of Qatar { 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 brcenter; echo
下边包车型大巴留言中富含关键字font color=red$keyword/font共font
color=red.$count./font条/center; } ? /tdtdp 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.trtd align=right colspan=2a
href=reply.php?job=reply&record=.$j.回复/aa
href=edit.php?record=.$j.编辑/aa 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
—————— 未完待续…

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图