留言板

轉載請註明出處:http://blog.csdn.net/u011569040/article/details/46993735


index.php
<html>
	<head>
    	<title>我的留言板</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
    	<center>
    	<?php include("menu.php");?>
		
        <h3>添加留言</h3>
		<form action="doAdd.php" method="post">
        <table width="380" border="0" cellpadding="4">
        	<tr>
            	<td>標題:</td>
                <td><input type="text" name="title"/></td>
            </tr>
            <tr>
            	<td>留言者:</td>
                <td><input type="text" name="author"/></td>
            </tr>
            <tr>
            	<td align="left" valign="top">留言內容:</td>
         		<td><textarea name="content" rows="5" cols="30"></textarea></td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                <input type="submit" value="提交"/>   
                <input type="reset" value="重置"/>
                </td>
            </tr>
        </table>
        </form>
		</center>



    </body>
</html>
show.php
<html>
	<head>
    	<title>我的留言板</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script>
			//彈框是否刪除
        	function dodel(id){
				if(confirm("確定要刪除嗎?")){
					window.location='del.php?id='+id;
				}	
			}
        </script>
    </head>
    <body>
    	<center>
    	<?php include("menu.php");?>
		
        <h3>添加留言</h3>
		<table border="1" width="900">
        	<tr>
            	<th>留言標題</th>
                <th>留言人</th>
                <th>留言內容</th>
                <th>IP地址</th>
                <th>留言時間</th>
                <th>操作 </th>
            </tr>
            <?php
            	//獲取留言信息,解析後輸出到表格中
				//1.從留言liuyan.txt信息文件中獲取留言信息
				$info=file_get_contents("liuyan.txt");
				//2.獲取留言內容最後三個@@@符號
				$info=rtrim($info,"@");
				
				if(strlen($info)>=8){
					//3.以@@@拆分留言信息爲一條一條的,拆分成留言數組
					$lylist = explode("@@@",$info);
					//4.遍歷留言信息數組,對每條留言做再次解析
					foreach($lylist as $k=>$v){
							$ly = explode("##",$v);
							echo "<tr>";
							echo "<td>{$ly[0]}</td>";
							echo "<td>{$ly[1]}</td>";
							echo "<td>{$ly[2]}</td>";
							echo "<td>{$ly[3]}</td>";
							echo "<td>".date("Y-m-d H:i:s",$ly[4]+8*3600)."</td>";
							echo "<td><a href='javascript:dodel({$k})'>刪除</a></td>";
							echo "</tr>";
					}
				}
				

			?>
        </table>
		</center>



    </body>
</html>
doAdd.php
<html>
	<head>
    	<title>我的留言板</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
    	<center>
    	<?php include("menu.php");?>
		
        <h3>添加留言</h3>
		<?php
        //1.獲取要添加的留言信息,並且補上其它輔助信息(ip地址、添加時間)
        $title=$_POST["title"];
        $author=$_POST["author"];
        $content=$_POST["content"];
        $ip=$_SERVER["REMOTE_ADDR"];
        $addtime = time();
        
        //2.拼裝(組裝)留言信息
        $ly = "{$title}##{$author}##{$content}##{$ip}##{$addtime}@@@";
        //echo $ly;
        //3.將留言信息追加到liuyan.txt文件中
		$info=file_get_contents("liuyan.txt");//得到以前的數據,連接後就不會覆蓋了
		file_put_contents("liuyan.txt",$info.$ly);//文件寫入(會覆蓋原有數據)
        //4.輸出留言成功
		echo "留言成功,謝謝!!!";
		?>
		</center>



    </body>
</html>
del.php
<html>
	<head>
    	<title>我的留言板</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
    	<center>
    	<?php include("menu.php");?>
		
        <h3>刪除留言</h3>
		
            <?php
            	//執行刪除指定id的留言信息
				//1.獲取要留言的id號
				$id = $_GET["id"];
				//2.從liuyan.txt中獲取留言信息
				$info=file_get_contents("liuyan.txt");
				//3.將留言信息以@@@爲符號拆分成留言數組
				$lylist = explode("@@@",$info);
				//4.使用unset刪除指定的id留言
				unset($lylist[$id]);
				//5.還原留言信息爲字符串,並寫回liuyan.txt
				$ninfo =  implode("@@@",$lylist);
				file_put_contents("liuyan.txt",$ninfo);
				echo "刪除成功";
				

			?>
        </table>
		</center>



    </body>
</html>
menu.php

<h2>我的留言板</h2>
        <a href="index.php">添加留言</a>
		<a href="show.php">查看留言</a>
		<hr width="90%"/>

下載

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章