当前位置: 编程技术>php
本页文章导读:
▪一个php作的文本留言本的例子(四)
这一节我们将dele.php和sys.php放上来. --------- //dele.php<html> <head> <title>删除留言</title> <style> <!-- A:link {text-decoration: none ; color:0000ff} A:visited {text-decoration: none; color:004080} .........
▪一个php作的文本留言本的例子(五)
现在我们来讲一下reply.php的代码: --------------------------------- //reply.php <? function check_strlen_long($txt) { $len=strlen($txt); $count=0; for ($i=0;$i<$len;$i++) { if (ord($txt[$i])<128) { $count=$count+1;} .........
▪一个php作的文本留言本的例子(一)
大家知道,数据库对于网络来说的重要性.由于cgi的复杂,现在asp和php+mysql已经成为主流.几乎所有的个人网页都要用到留言本,可是申请的留言本很不稳定.这为网上的交流带来了诸多不便.所以,.........
[1]一个php作的文本留言本的例子(四)
来源: 互联网 发布时间: 2013-11-30
这一节我们将dele.php和sys.php放上来.
---------
//dele.php<html>
<head>
<title>删除留言</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}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<?
require("sys.php");
if ($Submit)
{
if ($password<>$managepwd)
{$errorm="<font color=red>密码错误</font>.无权操作..";}
else
{
$content=file($guestfile);
$message=$content[$record-1];
$count=count($content);
if ($dele=="delreply")
{
$replylen=strlen(strstr($message,"<!--reply>"));
$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 "<meta http-equiv=Refresh content="1;url=guest.php">";
exit;
}
}// end ifSubmit
$content=file($guestfile);
$message=$content[$record-1];
$found=ereg("<!--reply>",$message);
?>
<body bgcolor="#FFFFFF" background="back.gif">
<? include("head.htm"); ?>
<table width="68%" border="1" cellpadding="5" align="center" cellspacing="0" bordercolor="#F2F2F2">
<form action=dele.php method=post>
<?
if ($errorm)
{
echo "<tr>";
echo "<td height=27>$errorm</td>";
echo "</tr>";
}
?>
<? echo $message ?>
<tr align="center">
<td height="37" bgcolor="#f0f0f0">
<?
if ($found)
{
echo "<input type=radio name=dele value=delall>";
echo "全部删除 ";
echo "<input type=radio name=dele value=delreply checked>";
echo "仅删除回复";
}
?>
<font color="#000000">管理密码</font>
<input type="password" name="password" size="10">
<input type=hidden name=record value=<? echo "$record";?>>
<input type="submit" name="Submit" value="我要删除了">
</td>
</tr>
</form>
</table>
<? include("bottom.htm"); ?>
</body>
</html>
------
//sys.php
<title>zihanonline</title><?
$managepwd='zihanonline';
$guestfile="guest.txt";
function check_strlen_long($txt)
{
$count=0;
$arrtemp=$txt;
$len=strlen($txt);
$txt=$txt.' ';
for ($i=0;$i<$len;$i++)
{
if (ord($txt[$i])<128)
{ $count=$count+1;}
if (ord($txt[$i])==10 or ord($txt[$i])==32)
{$count=0;}
if ($count>=70)
{
for ($j=$i;$j<$len;$j++)
{
$txt[$j+1]=$arrtemp[$j];
}
$txt[$i]="n";
$len=$len+1;
$txt[$len]=$arrtemp[$len-1];
$count=0;
$arrtemp=$txt;
}//end if count
}
$txt=trim($txt);
return $txt;
}//end function
function encode ($txt)
{
$txt=strip_tags($txt);
$txt=htmlspecialchars($txt);
$message=StripSlashes($txt);
return $message;
}
function ubb($txt)
{
}
?>
<body bgcolor="#FFFFFF" background="back.gif">
----------
注意sys.php中的" $managepwd='zihanonline' "一栏中等号后的是留言本的管理密码号,此时是默认的zihanonline.您可以修改为自己的号码.
未完待续...
---------
//dele.php<html>
<head>
<title>删除留言</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}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<?
require("sys.php");
if ($Submit)
{
if ($password<>$managepwd)
{$errorm="<font color=red>密码错误</font>.无权操作..";}
else
{
$content=file($guestfile);
$message=$content[$record-1];
$count=count($content);
if ($dele=="delreply")
{
$replylen=strlen(strstr($message,"<!--reply>"));
$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 "<meta http-equiv=Refresh content="1;url=guest.php">";
exit;
}
}// end ifSubmit
$content=file($guestfile);
$message=$content[$record-1];
$found=ereg("<!--reply>",$message);
?>
<body bgcolor="#FFFFFF" background="back.gif">
<? include("head.htm"); ?>
<table width="68%" border="1" cellpadding="5" align="center" cellspacing="0" bordercolor="#F2F2F2">
<form action=dele.php method=post>
<?
if ($errorm)
{
echo "<tr>";
echo "<td height=27>$errorm</td>";
echo "</tr>";
}
?>
<? echo $message ?>
<tr align="center">
<td height="37" bgcolor="#f0f0f0">
<?
if ($found)
{
echo "<input type=radio name=dele value=delall>";
echo "全部删除 ";
echo "<input type=radio name=dele value=delreply checked>";
echo "仅删除回复";
}
?>
<font color="#000000">管理密码</font>
<input type="password" name="password" size="10">
<input type=hidden name=record value=<? echo "$record";?>>
<input type="submit" name="Submit" value="我要删除了">
</td>
</tr>
</form>
</table>
<? include("bottom.htm"); ?>
</body>
</html>
------
//sys.php
<title>zihanonline</title><?
$managepwd='zihanonline';
$guestfile="guest.txt";
function check_strlen_long($txt)
{
$count=0;
$arrtemp=$txt;
$len=strlen($txt);
$txt=$txt.' ';
for ($i=0;$i<$len;$i++)
{
if (ord($txt[$i])<128)
{ $count=$count+1;}
if (ord($txt[$i])==10 or ord($txt[$i])==32)
{$count=0;}
if ($count>=70)
{
for ($j=$i;$j<$len;$j++)
{
$txt[$j+1]=$arrtemp[$j];
}
$txt[$i]="n";
$len=$len+1;
$txt[$len]=$arrtemp[$len-1];
$count=0;
$arrtemp=$txt;
}//end if count
}
$txt=trim($txt);
return $txt;
}//end function
function encode ($txt)
{
$txt=strip_tags($txt);
$txt=htmlspecialchars($txt);
$message=StripSlashes($txt);
return $message;
}
function ubb($txt)
{
}
?>
<body bgcolor="#FFFFFF" background="back.gif">
----------
注意sys.php中的" $managepwd='zihanonline' "一栏中等号后的是留言本的管理密码号,此时是默认的zihanonline.您可以修改为自己的号码.
未完待续...
[2]一个php作的文本留言本的例子(五)
来源: 互联网 发布时间: 2013-11-30
现在我们来讲一下reply.php的代码:
---------------------------------
//reply.php
<?
function check_strlen_long($txt)
{
$len=strlen($txt);
$count=0;
for ($i=0;$i<$len;$i++)
{
if (ord($txt[$i])<128)
{ $count=$count+1;}
if (ord($txt[$i])==10 or ord($txt[$i])==32)
{$count=0;}
if ($count>=60)
{
$txt[$i]="n";
$count=0;
}
}
return $txt;
}
function encode ($txt)
{
$txt=strip_tags($txt);
$txt=htmlspecialchars($txt);
$message=StripSlashes($txt);
return $message;
}
$content=file("guest.txt");
$disptext=$content[$record-1];
if ($job=="addreply" and $replyname!="" and $replycontent!="")
{
$content=file("guest.txt");
$count=count($content);
$time = date(Y年m月d日H小时i分);
$ip=$REMOTE_ADDR;
$replycontent=StripSlashes($replycontent);
$replyname=encode($replyname);
$replycontent=htmlspecialchars($replycontent);
$replycontent=check_strlen_long($replycontent);
$replycontent=nl2br($replycontent);
$replycontent=ereg_replace(chr(10),"",$replycontent);
$content[$record-1]=substr($content[$record-1],0,strlen($content[$i])-1); $content[$record-1]=$content[$record-1]."<!--reply><tr><td colspan=4><ul><font color=#AB00E1>回复内容:</font><br>".$replycontent."<br>回复人大名:".$replyname."<br><font color=#CC33FF>时间:$time 来自:$ip</font></ul><hr size=1 color=blue></td></tr>n";
$fp=fopen("guest.txt","w");
for ($i=0;$i<$count;$i++)
{
fputs($fp,$content[$i],strlen($content[$i]));
}
echo "<meta http-equiv=Refresh content=1;url=guest.php>";
exit;
}
?>
<title>zihanonline</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: 10p}
TH {FONT-SIZE: 10pt}
TD {FONT-SIZE: 10pt}
-->
</style>
<body bgcolor="#FFFFFF" background="back.gif">
<div align=center >
<? include('head.htm');?>
<table border= 1 width= 65% height= 169 cellpadding="8" cellspacing="0" bordercolor="#E3E3E3" >
<form method= POST action=reply.php >
<?
if ($Submit)
{
if ($replyname=="" or $replycontent=="")
{
echo"<tr align=left valign=middle bgcolor=#F0F0F0> ";
echo"<td width= 100% height= 31 > ";
echo "<font color=red>出错了</font>回复人姓名和回复内容必填!";
echo"</td>";
echo"</tr>";
}
}
?>
<? echo $disptext ?>
<tr align="left" valign="middle" bgcolor="#F0F0F0">
<td width= 100% height= 31 bgcolor="#FFFFFF" > 回复大名
<input type= text name= replyname size= 20 >
</td>
</tr>
<tr valign="middle">
<td width= 100% height= 26 align= left bgcolor="#f0f0f0" >
<p>回复内容</p>
</td>
</tr>
<tr align="center">
<td width= 100% height= 52 valign= top bgcolor="#FFFFFF" >
<textarea rows= 6 name= replycontent cols= 46 wrap="VIRTUAL" ></textarea>
</td>
</tr>
<tr valign="middle" align="center" bgcolor="#F0F0F0">
<td width= 100% height= 14 bgcolor="#f0f0f0" >
<input type=hidden name=job value=addreply>
<input type=hidden name=record value=<? echo $record ?>>
<input type= submit value= 提交 name=Submit >
<input type=reset value= 重写 name= B2 >
</td>
</tr>
</form>
</table>
<?include('bottom.htm');?>
</div>
</body>
</html>
------------------
到此为止,php的代码我们已经写完,剩下的是您要作一个留言本的本头和底部
您可以设计任何的样式.不过记得在本头上面要有至少3个连接:查看 返回主页
发邮件.这样您的留言本系统才算完整.不过由于这是一文本的留言本,所以您不用担心数据库的问题,您只要再写一个guest.txt的文件就完整了.虽然这个留言本没有mysql等等,可是功能仍然不错.而且是完全属于您自己的留言本.好了,下一节我们将为您讲述guest.txt的建立和上传留言本的几个重要步骤.
未完待续...
---------------------------------
//reply.php
<?
function check_strlen_long($txt)
{
$len=strlen($txt);
$count=0;
for ($i=0;$i<$len;$i++)
{
if (ord($txt[$i])<128)
{ $count=$count+1;}
if (ord($txt[$i])==10 or ord($txt[$i])==32)
{$count=0;}
if ($count>=60)
{
$txt[$i]="n";
$count=0;
}
}
return $txt;
}
function encode ($txt)
{
$txt=strip_tags($txt);
$txt=htmlspecialchars($txt);
$message=StripSlashes($txt);
return $message;
}
$content=file("guest.txt");
$disptext=$content[$record-1];
if ($job=="addreply" and $replyname!="" and $replycontent!="")
{
$content=file("guest.txt");
$count=count($content);
$time = date(Y年m月d日H小时i分);
$ip=$REMOTE_ADDR;
$replycontent=StripSlashes($replycontent);
$replyname=encode($replyname);
$replycontent=htmlspecialchars($replycontent);
$replycontent=check_strlen_long($replycontent);
$replycontent=nl2br($replycontent);
$replycontent=ereg_replace(chr(10),"",$replycontent);
$content[$record-1]=substr($content[$record-1],0,strlen($content[$i])-1); $content[$record-1]=$content[$record-1]."<!--reply><tr><td colspan=4><ul><font color=#AB00E1>回复内容:</font><br>".$replycontent."<br>回复人大名:".$replyname."<br><font color=#CC33FF>时间:$time 来自:$ip</font></ul><hr size=1 color=blue></td></tr>n";
$fp=fopen("guest.txt","w");
for ($i=0;$i<$count;$i++)
{
fputs($fp,$content[$i],strlen($content[$i]));
}
echo "<meta http-equiv=Refresh content=1;url=guest.php>";
exit;
}
?>
<title>zihanonline</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: 10p}
TH {FONT-SIZE: 10pt}
TD {FONT-SIZE: 10pt}
-->
</style>
<body bgcolor="#FFFFFF" background="back.gif">
<div align=center >
<? include('head.htm');?>
<table border= 1 width= 65% height= 169 cellpadding="8" cellspacing="0" bordercolor="#E3E3E3" >
<form method= POST action=reply.php >
<?
if ($Submit)
{
if ($replyname=="" or $replycontent=="")
{
echo"<tr align=left valign=middle bgcolor=#F0F0F0> ";
echo"<td width= 100% height= 31 > ";
echo "<font color=red>出错了</font>回复人姓名和回复内容必填!";
echo"</td>";
echo"</tr>";
}
}
?>
<? echo $disptext ?>
<tr align="left" valign="middle" bgcolor="#F0F0F0">
<td width= 100% height= 31 bgcolor="#FFFFFF" > 回复大名
<input type= text name= replyname size= 20 >
</td>
</tr>
<tr valign="middle">
<td width= 100% height= 26 align= left bgcolor="#f0f0f0" >
<p>回复内容</p>
</td>
</tr>
<tr align="center">
<td width= 100% height= 52 valign= top bgcolor="#FFFFFF" >
<textarea rows= 6 name= replycontent cols= 46 wrap="VIRTUAL" ></textarea>
</td>
</tr>
<tr valign="middle" align="center" bgcolor="#F0F0F0">
<td width= 100% height= 14 bgcolor="#f0f0f0" >
<input type=hidden name=job value=addreply>
<input type=hidden name=record value=<? echo $record ?>>
<input type= submit value= 提交 name=Submit >
<input type=reset value= 重写 name= B2 >
</td>
</tr>
</form>
</table>
<?include('bottom.htm');?>
</div>
</body>
</html>
------------------
到此为止,php的代码我们已经写完,剩下的是您要作一个留言本的本头和底部
您可以设计任何的样式.不过记得在本头上面要有至少3个连接:查看 返回主页
发邮件.这样您的留言本系统才算完整.不过由于这是一文本的留言本,所以您不用担心数据库的问题,您只要再写一个guest.txt的文件就完整了.虽然这个留言本没有mysql等等,可是功能仍然不错.而且是完全属于您自己的留言本.好了,下一节我们将为您讲述guest.txt的建立和上传留言本的几个重要步骤.
未完待续...
[3]一个php作的文本留言本的例子(一)
来源: 互联网 发布时间: 2013-11-30
大家知道,数据库对于网络来说的重要性.由于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=/index.html"mailto:$email\"><!--email>$email<!--endemail></a>"."$space";}
if ($homepage !="http://")
{$guestcontent=$guestcontent."<font color=#9900CC>主页:</font>$hompage<a href=/index.html"$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="/blog_article/guest.html">
<?
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=/blog_article/guest/page/$i/gt;.html".$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=/blog_article/reply/job/reply/amp;record/.html".$j.">回复</a> <a href=/blog_article/edit/record/.html".$j.">编辑</a> <a href=/blog_article/dele/record/.html".$j.">删除</a> 第<font color=red>$j</font>条</td></tr>";
$text.=$content[$j-1];
//数组找下标从0开始.
}
echo "$text";
?>
</table>
<?
include('bottom.htm');
?>
</body>
</html>
------------------
未完待续...
但是,免费的个人主页支持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=/index.html"mailto:$email\"><!--email>$email<!--endemail></a>"."$space";}
if ($homepage !="http://")
{$guestcontent=$guestcontent."<font color=#9900CC>主页:</font>$hompage<a href=/index.html"$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="/blog_article/guest.html">
<?
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=/blog_article/guest/page/$i/gt;.html".$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=/blog_article/reply/job/reply/amp;record/.html".$j.">回复</a> <a href=/blog_article/edit/record/.html".$j.">编辑</a> <a href=/blog_article/dele/record/.html".$j.">删除</a> 第<font color=red>$j</font>条</td></tr>";
$text.=$content[$j-1];
//数组找下标从0开始.
}
echo "$text";
?>
</table>
<?
include('bottom.htm');
?>
</body>
</html>
------------------
未完待续...
最新技术文章: