首先是Index页面效果图

index.php

<?php
header('content-type:text/html;charset=utf-8');
date_default_timezone_set('PRC');
$filename="msg.txt";
$msgs=[];
//检测文件是否存在
if(file_exists($filename)){
//读取文件中的内容
$string=file_get_contents($filename);
if(strlen($string)>0){
$msgs=unserialize($string);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-ui"></script>
<link href="http://www.francescomalagrino.com/BootstrapPageGenerator/3/css/bootstrap-combined.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div class="page-header">
<h1>
简易留言板-<span>V1.0</span>
</h1>
</div>
<div class="hero-unit">
<h1>
Hello, world!
</h1>
<p>
这是一个可视化布局模板, 你可以点击模板里的文字进行修改, 也可以通过点击弹出的编辑框进行富文本修改. 拖动区块能实现排序.
</p>
<p>
<a rel="nofollow" class="btn btn-primary btn-large" href="#">参看更多 »</a>
</p>
</div>
<?php if(is_array($msgs)&&count($msgs)>0):?>
<table class="table">
<thead>
<tr>
<th>
编号
</th>
<th>
用户名
</th>
<th>
标题
</th>
<th>
时间
</th>
<th>
内容
</th>
<th>
操作
</th>
</tr>
</thead>
<tbody>
<?php $i=1;foreach($msgs as $key=>$val):?>
<tr class="success">
<td>
<?php echo $i++;?>
</td>
<td>
<?php echo $val['username'];?>
</td>
<td>
<?php echo $val['title'];?>
</td>
<td>
<?php echo date("m/d/Y H:i:s",$val['time']);?>
</td>
<td>
<?php echo $val['content'];?>
</td>
<td>
<a href="edit.php?id=<?php echo $key;?>">编辑</a>|<a href="#" onclick="show_confirm(<?php echo $key;?>)">删除</a>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php endif;?>
<input type="button" class="btn btn-primary btn-lg" name="pubMsg" value="我要留言" onclick="window.location.href='add.php'"/>
</div>
</div>
</div>
<script type="text/javascript">
function show_confirm(key){
var r=confirm("确定删除吗?");
if (r==true){
location.href='delete.php?id='+key;
}
}
</script>
</body>
</html>

然后是新增留言页面效果图

add.php

<?php
header('content-type:text/html;charset=utf-8');
date_default_timezone_set('PRC');
$filename="msg.txt";
$msgs=[];
//检测文件是否存在
if(file_exists($filename)){
//读取文件中的内容
$string=file_get_contents($filename);
if(strlen($string)>0){
$msgs=unserialize($string);
}
}
//检测用户是否点击了提交按钮
if(isset($_POST['addMsg'])){
$username=$_POST['username'];
$title=strip_tags($_POST['title']);
$content=strip_tags($_POST['content']);
$time=time();
//将其组成关联数组
$data=compact('username','title','content','time');
array_push($msgs,$data);
$msgs=serialize($msgs);
if(file_put_contents($filename,$msgs)){
echo "<script>alert('留言成功!');location.href='index.php';</script>";
}else{
echo "<script>alert('留言失败!');location.href='index.php';</script>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-ui"></script>
<link href="http://www.francescomalagrino.com/BootstrapPageGenerator/3/css/bootstrap-combined.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div class="page-header">
<h1>
简易留言板-<span>V1.0</span>
</h1>
</div>
<div class="hero-unit">
<h1>
你终于来了!
</h1>
<p>
这是一个添加留言的留言板,你在下面愉快的留言吧!
</p>
<p>
<a rel="nofollow" class="btn btn-primary btn-large" href="#">参看更多 »</a>
</p>
</div>
<form action="#" method="post">
<fieldset>
<legend>发布</legend>
<label>用户名</label><input type="text" name="username" required />
<label>标题</label><input type="text" name="title" required />
<label>内容</label><textarea name="content" rows="5" cols="30" required></textarea>
<hr>
<input type="submit" class="btn btn-primary btn-lg" name="addMsg" value="发布留言"/>
<input type="button" class="btn btn-primary btn-lg" value="查看留言" onclick="window.location.href='index.php'"/>
</fieldset>
</form>
</div>
</div>
</div>
</body>
</html>

编辑留言页面

edit.php

<?php
header('content-type:text/html;charset=utf-8');
date_default_timezone_set('PRC');
$filename="msg.txt";
$msgs=[];
$id=$_GET['id'];//获取id
//检测文件是否存在
if(file_exists($filename)){
//读取文件中的内容
$string=file_get_contents($filename);
if(strlen($string)>0){
$msgs=unserialize($string);
}
}
//获取已有的留言信息
$username=$msgs[$id]['username'];
$title=strip_tags($msgs[$id]['title']);
$content=strip_tags($msgs[$id]['content']);
$time=$msgs[$id]['time'];
//检测用户是否点击了编辑按钮
if(isset($_POST['editMsg'])){
//将修改后的留言写入文档
$msgs[$id]['username']=$_POST['username'];
$msgs[$id]['title']=strip_tags($_POST['title']);
$msgs[$id]['content']=strip_tags($_POST['content']);
$msgs[$id]['time']=time();
$msgs=serialize($msgs);
if(file_put_contents($filename,$msgs)){
echo "<script>alert('编辑成功!');location.href='index.php';</script>";
}else{
echo "<script>alert('编辑失败!');location.href='index.php';</script>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-ui"></script>
<link href="http://www.francescomalagrino.com/BootstrapPageGenerator/3/css/bootstrap-combined.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div class="page-header">
<h1>
简易留言板-<span>V1.0</span>
</h1>
</div>
<div class="hero-unit">
<h1>
再来修改下~
</h1>
<p>
这是用来修改留言的地方哦!
</p>
<p>
<a rel="nofollow" class="btn btn-primary btn-large" href="#">参看更多 »</a>
</p>
</div>
<form action="#" method="post">
<fieldset>
<legend>编辑</legend>
<label>用户名</label><input type="text" name="username" value="<?php echo $username;?>" required />
<label>标题</label><input type="text" name="title" value="<?php echo $title;?>" required />
<label>内容</label><textarea name="content" rows="5" cols="30" required><?php echo $content;?></textarea>
<hr>
<input type="submit" class="btn btn-primary btn-lg" name="editMsg" value="编辑完成"/>
<input type="button" class="btn btn-primary btn-lg" value="查看留言" onclick="window.location.href='index.php'"/>
</fieldset>
</form>
</div>
</div>
</div>
</body>
</html>

此时储存的留言信息:msg.txt

a:2:{i:3;a:4:{s:8:"username";s:3:"cyy";s:5:"title";s:12:"cyy又来了";s:7:"content";s:27:"cyy经常来留言!!!";s:4:"time";i:1565510381;}i:4;a:4:{s:8:"username";s:3:"cyy";s:5:"title";s:17:"cyy2020第一踩~";s:7:"content";s:17:"cyy2020第一踩~";s:4:"time";i:1578723602;}}

php实现简易留言板效果的更多相关文章

  1. DOM操作相关案例 模态对话框,简易留言板,js模拟选择器hover,tab选项卡,购物车案例

    1.模态框案例 需求: 打开网页时有一个普通的按钮,点击当前按钮显示一个背景图,中心并弹出一个弹出框,点击X的时候会关闭当前的模态框 代码如下: <!DOCTYPE html> <h ...

  2. JSP简易留言板

    写在前面 在上篇博文JSP内置对象中介绍JSP的9个内置对象的含义和常用方法,但都是比较理论的知识.今天为大家带来一个小应用,用application制作的简易留言板. 包括三个功能模块:留言提交.留 ...

  3. 原生node实现简易留言板

    原生node实现简易留言板 学习node,实现一个简单的留言板小demo 1. 使用模块 http模块 创建服务 fs模块 操作读取文件 url模块 便于path操作并读取表单提交数据 art-tem ...

  4. Flask学习之旅--简易留言板

    一.写在前面 正所谓“纸上得来终觉浅,方知此事要躬行”,在看文档和视频之余,我觉得还是要动手做点什么东西才能更好地学习吧,毕竟有些东西光看文档真的难以理解,于是就试着使用Flask框架做了一个简易留言 ...

  5. 微信小程序实现简易留言板

    微信小程序现在很火,于是也就玩玩,做了一个简易的留言板,让大家看看,你们会说no picture you say a j8 a,好吧先上图. 样子就是的,功能一目了然,下面我们就贴实现的代码,首先是H ...

  6. 用js做一个简单的留言板效果

    html部分: 1: <!DOCTYPE> 2: <html lang="zh-en"> 3: <head> 4: <title>j ...

  7. vue实现简易留言板

    首先引入vue.js <script src="vue.js"></script> 布局 <div id="div"> &l ...

  8. js简易留言板

      <!DOCTYPE html>   <html lang="en">   <head>   <meta charset="U ...

  9. js 实现简易留言板功能

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. shell脚本 监控ps 不存在则重启

    监控 tomcat ,如果自动停止了,则重新启动 #!/bin/bash Start=/usr/local/apache-tomcat-8.0.24/bin/startup.sh Url=" ...

  2. [Redis-CentOS7]Redis数据持久化(八)

    配置文件位置 /ect/redis.conf RDB存储配置 save 900 1 # 900秒之内发生一次写操作保存 save 300 10 # 300秒内写10次保存 save 60 10000 ...

  3. Java源码系列1——ArrayList

    本文简单介绍了 ArrayList,并对扩容,添加,删除操作的源代码做分析.能力有限,欢迎指正. ArrayList是什么? ArrayList 就是数组列表,主要用来装载数据.底层实现是数组 Obj ...

  4. StackExchange.Redis 之 List队列 类型示例

    //从第1个开始,依次向左插入值.如果键不存在,先创建再插入值 队列形式 先进后出,后进先出 //插入后形式  <-- 10,9,8,7,6,5,4,3,2,1 <-- 方向向左依次进行 ...

  5. java设计模式 - 单例模式(干货)

    深度讲解23种设计模式,力争每种设计模式都刨析到底.废话不多说,开始第一种设计模式 - 单例. 作者已知的单例模式有8种写法,而每一种写法,都有自身的优缺点. 1,使用频率最高的写法,废话不多说,直接 ...

  6. springboot 查看H2数据库

    1  再application.properties文件中,添加 spring.h2.console.enabled=true 2 再浏览器中打开: http://localhost:8080/h2- ...

  7. Java Web 笔记(4)

    11.Filter (重点) Filter:过滤器 ,用来过滤网站的数据: 处理中文乱码 登录验证-. Filter开发步骤: 导包 编写过滤器 导包不要错 实现Filter接口,重写对应的方法即可 ...

  8. IE浏览器中IFrame被加载两次问题的解决-sunziren

    本文为作者sunziren原创,首发博客园,转载请注明出处. 昨天遇到了一个问题,先上代码. var content = '<iframe src="www.baidu.com&quo ...

  9. opencv —— 调用摄像头采集图像 VideoCapture capture(0);

    如果要调用摄像头进行视频采集,将代码 VideoCapture capture("C:/Users/齐明洋/Desktop/1.mp4"); 中的 "C:/Users/齐 ...

  10. 报表生成(POI,jquery.table2excel.js,Echarts)

    最近公司要弄个报表相关的功能,话不多说,先上图 前一种是POI 生成的,后一种是Echarts生成的.报表我想大家都不陌生,基本上在公司业务中都会使用到.先说说POI,jquery.table2exc ...