PHP文本式留言板——php經典執行個體

來源:互聯網
上載者:User

標籤:content   dump   儲存   input   功能   file   mit   ddr   執行個體   

檔案結構:

index.php  首頁和添加頁

show.php  查看留言頁

ly.db  文本儲存頁

doAdd.php  添加功能頁

doDel.php  刪除功能頁

 

 index.php

 1 <html> 2     <head> 3         <title>文本式留言板</title> 4         <meta charset=‘utf-8‘ /> 5     </head> 6     <body> 7         <center> 8             <h1>文本式留言板</h1> 9             <a href=‘index.php‘>添加留言</a>10             &nbsp;&nbsp;&nbsp;&nbsp;11             <a href=‘show.php‘>查看留言</a>12             <hr/>13             <form action=‘doAdd.php‘ method=‘post‘>14                 <table  width=‘500‘ cellpadding=‘10‘ >15                     <tr>16                         <td align=‘right‘>標題</td>17                         <td><input type=‘text‘ name=‘title‘ size=‘30‘ /></td>18                     </tr>19                     <tr>20                         <td align=‘right‘>作者</td>21                         <td><input type=‘text‘ name=‘author‘ /></td>22                     </tr>23                     <tr>24                         <td align=‘right‘>內容</td>25                         <td><textarea name=‘content‘ cols=‘50‘ rows=‘6‘></textarea></td>26                     </tr>27                     <tr align=‘center‘>28                         <td colspan=‘2‘>29                             <input type=‘submit‘ value=‘添加‘ />30                             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;31                             <input type=‘reset‘ value=‘清空‘ />32                         </td>33                     </tr>34                 </table>35             </form>36         </center>37     </body>38 </html>

 

 show.php

 1 <html> 2     <head> 3         <title>文本式留言板</title> 4         <meta charset=‘utf-8‘ /> 5     </head> 6     <body> 7         <center> 8             <h1>文本式留言板</h1> 9             <a href=‘index.php‘>添加留言</a>10             &nbsp;&nbsp;&nbsp;&nbsp;11             <a href=‘show.php‘>查看留言</a>12             <hr/>13             14             <table  width=‘800‘ border=‘1‘ cellpadding=‘5‘ >15                 <tr>16                     <th>標題</th>17                     <th>作者</th>18                     <th>內容</th>19                     <th>i p</th>20                     <th>時間</th>21                     <th>操作</th>22                 </tr>23                 <?php24                     //讀檔案25                     $info=rtrim(file_get_contents("ly.db"),"@");26                     if($info != ""){27                         //拆分28                         $list=explode("@@",$info);29                         30                         //var_dump($list);31                         //遍曆32                         foreach($list as $k=>$v){33                         34                             //拆分v35                             $oncely=explode("##",$v);36 37                             echo "<tr>";38                                 echo "<td>{$oncely[0]}</td>";39                                 echo "<td>{$oncely[1]}</td>";40                                 echo "<td>{$oncely[2]}</td>";41                                 echo "<td>{$oncely[3]}</td>";42                                 echo "<td>{$oncely[4]}</td>";43                                 echo "<td><a href=‘doDel.php?k={$k}‘>刪除</a></td>";44                             echo "</tr>";45                         }46                     47                     }else{48                         echo "無資料";49                     }50                     51                 52                 53                 ?>54             </table>55         56         </center>57     </body>58 </html>

 

doAdd.php

 1 <?php 2     if(empty($_POST)){ 3         //如果不是post提交自動跳回 4         header("location:index.php"); 5         die; 6     } 7     //標題不可為空 8     if($_POST[‘title‘]==""){ 9         echo "標題不可為空!";10         header("refresh:1;url=index.php");11         die;12     }13     //作者不可為空14     if($_POST[‘author‘]==""){15         echo "作者不可為空!";16         header("refresh:1;url=index.php");17         die;18     }19     //內容不可為空20     if($_POST[‘content‘]==""){21         echo "內容不可為空!";22         header("refresh:1;url=index.php");23         die;24     }25     26     //拼接字串27     $info=$_POST[‘title‘]."##".$_POST[‘author‘]."##".$_POST[‘content‘].28     "##".$_SERVER[‘REMOTE_ADDR‘]."##".date("Y-m-d H:i")."@@";29     30     //寫入db檔案31     file_put_contents("ly.db",$info,FILE_APPEND);32     33     echo "ok";34     header("refresh:1;url=index.php");35     36     37 38 ?>

 

doDel.php

 1 <?php 2  3     if(!isset($_GET[‘k‘])){ 4         //k沒傳過來直接跳回 5         header("location:show.php"); 6         die; 7     } 8      9     $k=$_GET[‘k‘];10     11     //讀檔案12     $info=rtrim(file_get_contents("ly.db"),"@");13     14     //拆分15     $list=explode("@@",$info);16     17     //刪除18     unset($list[$k]);19     20     if(count($list)>0){21         //數組轉字串回填到db檔案22         file_put_contents("ly.db",implode("@@",$list)."@@");23     }else{24         //數組為空白回填一個Null 字元25         file_put_contents("ly.db","");26     }27     28     echo "ok";29     header("refresh:1;url=show.php"); 30 31 ?>

 :http://files.cnblogs.com/files/wordblog/wblyb.zip

PHP文本式留言板——php經典執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.