分享
 
 
 

PHP+TEXT留言本(二)

王朝php·作者佚名  2008-12-28
窄屏简体版  字體: |||超大  

上一次我們研究了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 = "&nbsp;";

$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="TxtEmail]$TxtEmail"."$space'mailto:$TxtEmail"><!--email>$TxtEmail<!--endemail></a>"."$space";}

if ($TxtHomepage !="http://")

{$Wcontent=$Wcontent."<font color=#9900CC>主頁:</font>$TxtHompage<a href="$TxtHomepage" 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(""","&quot;",$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="edit.php" 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代碼中,這樣寫起代碼很愜意.

待續...

 
 
 
免責聲明:本文為網絡用戶發布,其觀點僅代表作者個人觀點,與本站無關,本站僅提供信息存儲服務。文中陳述內容未經本站證實,其真實性、完整性、及時性本站不作任何保證或承諾,請讀者僅作參考,並請自行核實相關內容。
上一次我們研究了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 = "&nbsp;"; $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="[url=mailto:$TxtEmail]$TxtEmail[/url]"."$space'mailto:$TxtEmail"><!--email>$TxtEmail<!--endemail></a>"."$space";} if ($TxtHomepage !="http://") {$Wcontent=$Wcontent."<font color=#9900CC>主頁:</font>$TxtHompage<a href="$TxtHomepage" 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(""","&quot;",$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="edit.php" 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代碼中,這樣寫起代碼很愜意. 待續...
2023年上半年GDP全球前十五強
 百态   2023-10-24
美眾議院議長啟動對拜登的彈劾調查
 百态   2023-09-13
上海、濟南、武漢等多地出現不明墜落物
 探索   2023-09-06
印度或要將國名改為「巴拉特」
 百态   2023-09-06
男子為女友送行,買票不登機被捕
 百态   2023-08-20
手機地震預警功能怎麽開?
 干货   2023-08-06
女子4年賣2套房花700多萬做美容:不但沒變美臉,面部還出現變形
 百态   2023-08-04
住戶一樓被水淹 還衝來8頭豬
 百态   2023-07-31
女子體內爬出大量瓜子狀活蟲
 百态   2023-07-25
地球連續35年收到神秘規律性信號,網友:不要回答!
 探索   2023-07-21
全球鎵價格本周大漲27%
 探索   2023-07-09
錢都流向了那些不缺錢的人,苦都留給了能吃苦的人
 探索   2023-07-02
倩女手遊刀客魅者強控制(強混亂強眩暈強睡眠)和對應控制抗性的關系
 百态   2020-08-20
美國5月9日最新疫情:美國確診人數突破131萬
 百态   2020-05-09
荷蘭政府宣布將集體辭職
 干货   2020-04-30
倩女幽魂手遊師徒任務情義春秋猜成語答案逍遙觀:鵬程萬裏
 干货   2019-11-12
倩女幽魂手遊師徒任務情義春秋猜成語答案神機營:射石飲羽
 干货   2019-11-12
倩女幽魂手遊師徒任務情義春秋猜成語答案昆侖山:拔刀相助
 干货   2019-11-12
倩女幽魂手遊師徒任務情義春秋猜成語答案天工閣:鬼斧神工
 干货   2019-11-12
倩女幽魂手遊師徒任務情義春秋猜成語答案絲路古道:單槍匹馬
 干货   2019-11-12
倩女幽魂手遊師徒任務情義春秋猜成語答案鎮郊荒野:與虎謀皮
 干货   2019-11-12
倩女幽魂手遊師徒任務情義春秋猜成語答案鎮郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手遊師徒任務情義春秋猜成語答案鎮郊荒野:指鹿為馬
 干货   2019-11-12
倩女幽魂手遊師徒任務情義春秋猜成語答案金陵:小鳥依人
 干货   2019-11-12
倩女幽魂手遊師徒任務情義春秋猜成語答案金陵:千金買鄰
 干货   2019-11-12
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有