留言板
2015-07-21 22:58
351 查看
转载请注明出处:/article/3711665.html
下载
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%"/>
下载
相关文章推荐
- 2015-7-21日总结
- 3.2 playbook tags
- Spring分布式事务
- 模拟请求
- POJ 2703:骑车与走路(动态数组)
- Power of Two
- 【leetcode-2】Add Two Numbers(C)
- 3.1 playbook语法实践
- Openssl base64命令
- linux常用c函数 数据结构及算法篇
- EF中加载实体的方式
- 使用ajax解决ie缓存问题
- 11G新特性 -- ASM Fast Mirror Resync
- 分享智慧石代码
- Web项目中使用JSTL标签问题
- python系列------计算机运算过程
- linux常用c函数 常用数学函数篇
- 获取txt文件指定行内容
- 枚举使用
- 进程和线程知识点