PHP+TEXT留言本(一)

大傢知道,數據庫對於網絡來說的重要性.由於cgi的復雜,現在asp和php+MySQL已經成為主流.幾乎所有的個人網頁都要用到留言本,可是申請的留言本很不穩定.這為網上的交流帶來瞭諸多不便.所以,希望擁有自己的留言本的朋友越來越多.
但是,免費的個人主頁支持asp和php的很少.筆者現在向您推薦動站指南,(http://)支持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 = “&nbsp;”;
$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=”$email“.”$space>mailto:$email”><!–email>$email<!–endemail></a>”.”$space”;}
if ($homepage !=”http://”)
{$guestcontent=$guestcontent.”<font color=#9900CC>主頁:</font>$hompage<a href=”$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>
“;
$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”>
<p align=”center”>&nbsp;
  <? 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>”;
      }
      ?>
      <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”>
          <p 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></p>
        </td>
      </tr>
      <tr bgcolor=”#F0F0F0″>
        <td colspan=”3″ height=”24″>
          <p align=”center”><font color=”#00FF00″>
            <input type=”submit” value=”發  送” name=”B1″>
            &nbsp;&nbsp;&nbsp;
            <input type=”reset” value=”重 寫” name=”B2″>
            </font></p>
        </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>
         

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *