首先是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. indexedDB 使用

    数据库的打开/新增/删除 initDB() { let _this = this; let obj = { id: 1, name: _this.addForm.content } let index ...

  2. android应用开发错误:Your project contains error(s),please fix them before running your

    重新打开ECLIPSE运行android项目,或者一段时间为运行ECLIPSE,打开后,发现新建项目都有红叉,以前的项目重新编译也有这问题,上网搜索按下面操作解决了问题 工程上有红叉,不知道少了什么, ...

  3. nginx 正向代理与反向代理

    一.介绍 反向代理:让Internet上的用户可以访问局域网内的资源,中间设置一个代理服务器,如下所示,红色圈是指局域网内的站点(myweb站点是我们的站点,例如iis).箭头不能反过来 正向代理:客 ...

  4. View Binding初探

    参考翻译:https://developer.android.google.cn/topic/libraries/view-binding View Binding是一项功能,使您可以更轻松地编写与视 ...

  5. 小程序封装request请求

    //request.js var host = 'https://www.xxx.com';//请求域名 module.exports = function (type, params, method ...

  6. mysql必知必会--了解SQL

    什么是数据库 数据库这个术语的用法很多,但就本书而言,数据库是一个以某种 有组织的方式存储的数据集合.理解数据库的一种最简单的办法是将其 想象为一个文件柜.此文件柜是一个存放数据的物理位置,不管数据是 ...

  7. 菜鸟linux

    //查看系统中文件的使用情况 df -h //查看当前目录下各个文件及目录占用空间大小 du -sh *//查看当期端口使用情况netstat -tlpn //find命令详见--https://ww ...

  8. Elasticsearch配置集群环境

    环境选择:            1.方案一:准备三台机器   每一台机器一个节点            2.方案二:准备一台机器   启动三个节点,用端口号区分即可            3.ES启 ...

  9. CSS中before、after伪类选择器的巧用

    大家好,今天给大家带来使用css中 before . after 实现两个效果,话不多说,我们先来看看, before 和 after 它们的作用是什么 选择器 作用 before 向选定的元素前插入 ...

  10. W25Q64BV(FLASH)(SPI)中文手册

    64兆位串行SPI FLASH存储器 1.常规介绍 W25Q64BV(64兆位)串行FLASH存储器为一个空间大小,引脚,功耗限制的系统提供解决方案.25Q系列的灵活性和性能良好超越了普通的串行FLA ...