当前位置: 编程技术>php
本页文章导读:
▪一个php作的文本留言本的例子(六)
这一节我将为大家讲述关于guest.txt的建立方法和上传的有关事项. ------- //guest.txt <tr><td><font color=#AB00E1>留言内容:</font><br><!--content>zihanonline<!--endcontent> <br>.........
▪一个php作的文本留言本的例子(二)
上一次我们研究了guest.php文件.具体的问题还要求读者朋友自己深入的去实践,而且需要一些工具书来学习,如果您一点php的知识都没有,笔者奉劝您就不要想下看了,笔者没有太多的时间和篇幅.........
▪一个php作的文本留言本的例子(三)
上两节我针对guest.php和edit.php作了讲述.需要注意的是php和html的区别: php通常是-->(1)<? echo("zihanonline");?> (2)<? php echo("zihanonline"); .........
[1]一个php作的文本留言本的例子(六)
来源: 互联网 发布时间: 2013-11-30
这一节我将为大家讲述关于guest.txt的建立方法和上传的有关事项.
-------
//guest.txt
<tr><td><font color=#AB00E1>留言内容:</font><br><!--content>zihanonline<!--endcontent> <br><font color=#6633FF>留言人大名:</font><!--name>zihanonline<!--endname> <font color=#9900CC>主页:</font><a href="http://xxx.com" target=new><!--homepage>http://xxx.com<!--endhomepage></a><br><font color=#0000FF>时间:2001年4月15日14小时06分 来自:<!--from><!--endfrom> xx.x.x.x</font><hr size=1></td></tr>
-------
上面是一个guest.txt的写入例子,您可以将他们放上去,然后看一看效果,再进行自己个性化的修改.循序渐进的实践是最最重要的.
一切都做好了,剩下的就是上传了.笔者以cuteftp为例,当您将一切都传到您的主页空间后,您需要有一个连接指向guest.php.这样您才可以让主页和留言本结合起来,另外一个最最重要的是,您要将guest.txt文件的属性改为666,这也是曾经折磨了笔者好一段日子的问题.具体做法是:上传了guest.txt后用鼠标右键点击
guest.txt后出现一串菜单选项,选CHMOD项,在manual方框内添入666,点"确定",好了,大功告成.您可以享受拥有自己的留言本的乐趣了.
全文完
-------
//guest.txt
<tr><td><font color=#AB00E1>留言内容:</font><br><!--content>zihanonline<!--endcontent> <br><font color=#6633FF>留言人大名:</font><!--name>zihanonline<!--endname> <font color=#9900CC>主页:</font><a href="http://xxx.com" target=new><!--homepage>http://xxx.com<!--endhomepage></a><br><font color=#0000FF>时间:2001年4月15日14小时06分 来自:<!--from><!--endfrom> xx.x.x.x</font><hr size=1></td></tr>
-------
上面是一个guest.txt的写入例子,您可以将他们放上去,然后看一看效果,再进行自己个性化的修改.循序渐进的实践是最最重要的.
一切都做好了,剩下的就是上传了.笔者以cuteftp为例,当您将一切都传到您的主页空间后,您需要有一个连接指向guest.php.这样您才可以让主页和留言本结合起来,另外一个最最重要的是,您要将guest.txt文件的属性改为666,这也是曾经折磨了笔者好一段日子的问题.具体做法是:上传了guest.txt后用鼠标右键点击
guest.txt后出现一串菜单选项,选CHMOD项,在manual方框内添入666,点"确定",好了,大功告成.您可以享受拥有自己的留言本的乐趣了.
全文完
[2]一个php作的文本留言本的例子(二)
来源: 互联网 发布时间: 2013-11-30
上一次我们研究了guest.php文件.具体的问题还要求读者朋友自己深入的去实践,而且需要一些工具书来学习,如果您一点php的知识都没有,笔者奉劝您就不要想下看了,笔者没有太多的时间和篇幅去逐句探究一个php文件的用途和意义.好的,接下来我们来作edit.php这个文件.
-----------
//edit.php
<?
if ($Submit)
{
if ($SavePassword=="on")
{setcookie("TxtPassword","$TxtPassword",time()+30*24*3600);}
else
{setcookie("TxtPassword");}
}
?>
<html>
<style type=text/css>
Td {FONT-SIZE: 10pt;}
TEXTAREA
{
FONT-FAMILY: "宋体";
FONT-SIZE: 10pt;
}
</style>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>修改留言</title>
<?
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 = "<tr><td><font color=#AB00E1>留言内容:</font><br><!--content>$TxtContent<!--endcontent> ";
$Wcontent=$Wcontent."<br><font color=#6633FF>留言人大名:</font><!--name>$TxtName<!--endname> ";
if ($TxtEmail !="")
{$Wcontent=$Wcontent."<br><font color=#9900CC>电子信箱</font><a href="mailto:$TxtEmail"><!--email>$TxtEmail<!--endemail></a>"."$space";}
if ($TxtHomepage !="http://")
{$Wcontent=$Wcontent."<font color=#9900CC>主页:</font>$TxtHompage<a href="/blog_article/$TxtHomepage/index.html" target=new><!--homepage>$TxtHomepage<!--endhomepage></a>";}
$Wcontent=$Wcontent."<br><font color=#0000FF>时间:$time 来自:<!--from>$TxtFrom<!--endfrom> ".$ip."</font>";
$Wcontent=ereg_replace(chr(10),"",$Wcontent);
$Wcontent=$Wcontent."<hr size=1></td></tr>";
$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 "<meta http-equiv=Refresh content="1;url=guest.php">";
exit;
}else {$errorm="留言人姓名和内容必填!!";}
}
else {$errorm="密码错误,只有管理员有权修改!!";}
}
?>
</head>
<body bgcolor="#FFFFFF" background="back.gif">
<? include('head.htm');?>
<div align="center">
<center>
<table border="1" width="68%" height="31" cellspacing="0" cellpadding="7" bordercolor="#E3E3E3">
<form action="/blog_article/edit.html" method=post>
<?
if ($errorm and $Submit)
{
echo"<tr>";
echo"<td height=40 colspan=4>";
echo"<font color=red>出错了,</font>$errorm";
echo"</td>";
echo"</tr>";
}
?>
<tr>
<td width="18%" height="37" bgcolor="#f0f0f0"><font color="#000000">留言大名</font></td>
<td width="39%" height="37" bgcolor="#FFFFFF">
<input type="text" name="TxtName" size="26" value=<?echo "$txtname"?>>
</td>
<td width="11%" height="37" bgcolor="#f0f0f0"><font color="#000000">来自</font></td>
<td width="32%" height="37" bgcolor="#FFFFFF">
<input type="text" name="TxtFrom" size="20" value=<?echo "$txtfrom"?>>
</td>
</tr>
<tr>
<td width="18%" height="31" bgcolor="#f0f0f0"><font color="#000000">主页地址</font></td>
<td width="39%" height="31" bgcolor="#FFFFFF">
<input type="text" name="TxtHomepage" size="26" value=<?echo "$txthomepage"?>>
</td>
<td width="11%" height="31" bgcolor="#f0f0f0"><font color="#000000">Email</font></td>
<td width="32%" height="31" bgcolor="#FFFFFF">
<input type="text" name="TxtEmail" size="20" value=<?echo "$txtemail"?>>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="31" colspan="4"><font color="#000000">留言内容</font></td>
</tr>
<tr bgcolor="#f0f0f0">
<td height="105" colspan="4" valign="middle" align="center">
<textarea rows="6" name="TxtContent" cols="50" wrap="VIRTUAL"><? echo "$txtcontent"?>
</textarea>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="40" colspan="4" valign="middle" align="center"> <font color="#000000">修改密码</font>
<input type="password" name="TxtPassword" size="10" value=<?echo "$TxtPassword"?>>
<font color="#000000">是否保存密码</font>
<input type="checkbox" name="SavePassword" value="on" checked>
<input type=hidden name=record value=<? echo "$record"?>>
<input type="submit" value="我要修改了" name="Submit">
</td>
</tr>
<? echo "$txtreply"?>
<input type=hidden name=TxtReply value="<? echo "$txtreply" ?>">
</form>
</table>
</center>
</div>
<?include('bottom.htm');?>
</body>
</html>
----------
该注明的地方我已作了诠释.php可以嵌入html代码中,这样写起代码很惬意.
待续...
-----------
//edit.php
<?
if ($Submit)
{
if ($SavePassword=="on")
{setcookie("TxtPassword","$TxtPassword",time()+30*24*3600);}
else
{setcookie("TxtPassword");}
}
?>
<html>
<style type=text/css>
Td {FONT-SIZE: 10pt;}
TEXTAREA
{
FONT-FAMILY: "宋体";
FONT-SIZE: 10pt;
}
</style>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>修改留言</title>
<?
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 = "<tr><td><font color=#AB00E1>留言内容:</font><br><!--content>$TxtContent<!--endcontent> ";
$Wcontent=$Wcontent."<br><font color=#6633FF>留言人大名:</font><!--name>$TxtName<!--endname> ";
if ($TxtEmail !="")
{$Wcontent=$Wcontent."<br><font color=#9900CC>电子信箱</font><a href="mailto:$TxtEmail"><!--email>$TxtEmail<!--endemail></a>"."$space";}
if ($TxtHomepage !="http://")
{$Wcontent=$Wcontent."<font color=#9900CC>主页:</font>$TxtHompage<a href="/blog_article/$TxtHomepage/index.html" target=new><!--homepage>$TxtHomepage<!--endhomepage></a>";}
$Wcontent=$Wcontent."<br><font color=#0000FF>时间:$time 来自:<!--from>$TxtFrom<!--endfrom> ".$ip."</font>";
$Wcontent=ereg_replace(chr(10),"",$Wcontent);
$Wcontent=$Wcontent."<hr size=1></td></tr>";
$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 "<meta http-equiv=Refresh content="1;url=guest.php">";
exit;
}else {$errorm="留言人姓名和内容必填!!";}
}
else {$errorm="密码错误,只有管理员有权修改!!";}
}
?>
</head>
<body bgcolor="#FFFFFF" background="back.gif">
<? include('head.htm');?>
<div align="center">
<center>
<table border="1" width="68%" height="31" cellspacing="0" cellpadding="7" bordercolor="#E3E3E3">
<form action="/blog_article/edit.html" method=post>
<?
if ($errorm and $Submit)
{
echo"<tr>";
echo"<td height=40 colspan=4>";
echo"<font color=red>出错了,</font>$errorm";
echo"</td>";
echo"</tr>";
}
?>
<tr>
<td width="18%" height="37" bgcolor="#f0f0f0"><font color="#000000">留言大名</font></td>
<td width="39%" height="37" bgcolor="#FFFFFF">
<input type="text" name="TxtName" size="26" value=<?echo "$txtname"?>>
</td>
<td width="11%" height="37" bgcolor="#f0f0f0"><font color="#000000">来自</font></td>
<td width="32%" height="37" bgcolor="#FFFFFF">
<input type="text" name="TxtFrom" size="20" value=<?echo "$txtfrom"?>>
</td>
</tr>
<tr>
<td width="18%" height="31" bgcolor="#f0f0f0"><font color="#000000">主页地址</font></td>
<td width="39%" height="31" bgcolor="#FFFFFF">
<input type="text" name="TxtHomepage" size="26" value=<?echo "$txthomepage"?>>
</td>
<td width="11%" height="31" bgcolor="#f0f0f0"><font color="#000000">Email</font></td>
<td width="32%" height="31" bgcolor="#FFFFFF">
<input type="text" name="TxtEmail" size="20" value=<?echo "$txtemail"?>>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="31" colspan="4"><font color="#000000">留言内容</font></td>
</tr>
<tr bgcolor="#f0f0f0">
<td height="105" colspan="4" valign="middle" align="center">
<textarea rows="6" name="TxtContent" cols="50" wrap="VIRTUAL"><? echo "$txtcontent"?>
</textarea>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="40" colspan="4" valign="middle" align="center"> <font color="#000000">修改密码</font>
<input type="password" name="TxtPassword" size="10" value=<?echo "$TxtPassword"?>>
<font color="#000000">是否保存密码</font>
<input type="checkbox" name="SavePassword" value="on" checked>
<input type=hidden name=record value=<? echo "$record"?>>
<input type="submit" value="我要修改了" name="Submit">
</td>
</tr>
<? echo "$txtreply"?>
<input type=hidden name=TxtReply value="<? echo "$txtreply" ?>">
</form>
</table>
</center>
</div>
<?include('bottom.htm');?>
</body>
</html>
----------
该注明的地方我已作了诠释.php可以嵌入html代码中,这样写起代码很惬意.
待续...
[3]一个php作的文本留言本的例子(三)
来源: 互联网 发布时间: 2013-11-30
上两节我针对guest.php和edit.php作了讲述.需要注意的是php和html的区别:
php通常是-->(1)<? echo("zihanonline");?>
(2)<? php
echo("zihanonline");
?>
(3)<script laanguage="php">
echo("zihanonline");
</script>
(4)<% echo("zihanonline");%>
等4种方式.不要混淆.
下面我们来研究信息管理:manage.php代码.
-----------
//manage.php<html>
<head>
<title>留言管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<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: 9p}
TH {FONT-SIZE: 9pt}
TD {FONT-SIZE: 9pt}
-->
</style>
</head>
<body bgcolor="#FFFFFF" background="back.gif">
<?
include('head.htm');
include("sys.php");
if ($password!=$managepwd and $dispflag)
{
echo "<meta http-equiv=Refresh content=5;url=guest.php>";
echo "<center>";
echo "<font color=red>密码错误!无法删除留言!</font>";
echo "<p>程序将在3秒返回</p>";
echo "<p> <a href=http://zihanonline.longcity.net>子汉在线</a>斑竹维护管理。</p>";
echo "<br>";
echo "</center>";
exit;
}
?>
<table width="445" border="0" align="center" bgcolor="#CCCCCC">
<form method="post" action="/blog_article/manage.html">
<?
if ($dispflag=="show")
{
$content = file($guestfile);
$count =count($content);
$text="";
for ($h=$count;$h>0;$h--)
{
$text=$text.'<tr><td>删除第'.$h."条留言:<input type=checkbox name=check$h value=$h></td></tr>nn";
$text=$text.$content[$h-1];
}
echo "$text";
}
?>
<input type=hidden name=password value=<? echo $password ?>>
<?
if ($submit)
{
if ($password!=$managepwd)
{
echo "<meta http-equiv=Refresh content=5;url=guest.php>";
echo "<center>";
echo "<font color=red>密码错误!无法删除留言!</font>";
echo "<p>程序将在3秒返回</p>";
echo "<p> <a href=http://zihanonline.longcity.net>子汉在线</a>斑竹维护管理。</p>";
echo "<br>";
echo "</center>";
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 "<meta http-equiv=Refresh content=5;url=guest.php>";
echo "<center>";
echo "<p><font color=red>留言已正确删除</font></p>";
echo "<p>程序将在3秒返回</p>";
echo "<p> <a href=http://zihanonline.longcity.net>子汉在线</a>斑竹维护管理。</p>";
echo "<br>";
echo "</center>";
exit;
}
}
?>
<tr>
<td bgcolor="#f0f0f0">
<p align=center>
<input type=submit value=删除 name=submit>
<input type=reset value=重写 name=reset>
</td>
<tr>
</form>
</table>
<?include('bottom.htm');?>
</body>
</html>
------------
未完待续...
php通常是-->(1)<? echo("zihanonline");?>
(2)<? php
echo("zihanonline");
?>
(3)<script laanguage="php">
echo("zihanonline");
</script>
(4)<% echo("zihanonline");%>
等4种方式.不要混淆.
下面我们来研究信息管理:manage.php代码.
-----------
//manage.php<html>
<head>
<title>留言管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<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: 9p}
TH {FONT-SIZE: 9pt}
TD {FONT-SIZE: 9pt}
-->
</style>
</head>
<body bgcolor="#FFFFFF" background="back.gif">
<?
include('head.htm');
include("sys.php");
if ($password!=$managepwd and $dispflag)
{
echo "<meta http-equiv=Refresh content=5;url=guest.php>";
echo "<center>";
echo "<font color=red>密码错误!无法删除留言!</font>";
echo "<p>程序将在3秒返回</p>";
echo "<p> <a href=http://zihanonline.longcity.net>子汉在线</a>斑竹维护管理。</p>";
echo "<br>";
echo "</center>";
exit;
}
?>
<table width="445" border="0" align="center" bgcolor="#CCCCCC">
<form method="post" action="/blog_article/manage.html">
<?
if ($dispflag=="show")
{
$content = file($guestfile);
$count =count($content);
$text="";
for ($h=$count;$h>0;$h--)
{
$text=$text.'<tr><td>删除第'.$h."条留言:<input type=checkbox name=check$h value=$h></td></tr>nn";
$text=$text.$content[$h-1];
}
echo "$text";
}
?>
<input type=hidden name=password value=<? echo $password ?>>
<?
if ($submit)
{
if ($password!=$managepwd)
{
echo "<meta http-equiv=Refresh content=5;url=guest.php>";
echo "<center>";
echo "<font color=red>密码错误!无法删除留言!</font>";
echo "<p>程序将在3秒返回</p>";
echo "<p> <a href=http://zihanonline.longcity.net>子汉在线</a>斑竹维护管理。</p>";
echo "<br>";
echo "</center>";
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 "<meta http-equiv=Refresh content=5;url=guest.php>";
echo "<center>";
echo "<p><font color=red>留言已正确删除</font></p>";
echo "<p>程序将在3秒返回</p>";
echo "<p> <a href=http://zihanonline.longcity.net>子汉在线</a>斑竹维护管理。</p>";
echo "<br>";
echo "</center>";
exit;
}
}
?>
<tr>
<td bgcolor="#f0f0f0">
<p align=center>
<input type=submit value=删除 name=submit>
<input type=reset value=重写 name=reset>
</td>
<tr>
</form>
</table>
<?include('bottom.htm');?>
</body>
</html>
------------
未完待续...
最新技术文章: