首先是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. ubuntu14.04安装mysql5.6.37

    摘抄这篇文档是为了记录自己的日常学习情况,方便以后查看.后边注明了来源,如有不对的地方,希望大家指正,谢谢! 首先从mysql官网上下载所需的离线包,我现在的版本是(mysql-5.6.37-linu ...

  2. mitmproxy--Cannot establish TLS with client (sni: e.crashlytics.com): TlsException("(-1, 'Unexpected EOF')",) 解决办法

    按崔哥(https://cuiqingcai.com/5391.html)的安装步骤一步步下来,会报这个错误: Cannot establish TLS with client (sni: e.cra ...

  3. Spark存储介绍

    目录 整体架构 存储相关类 应用启动时 增删改后更新元数据 获取数据存放位置 数据块的删除 RDD存储调用 数据读取 数据写入 cache & checkpoint Reference 记录一 ...

  4. opencv —— approxPolyDP 生成逼近曲线

    生成逼近曲线:approxPolyDP 函数 该函数采用 Douglas-Peucker 算法(也称迭代终点拟合算法).可以有效减少多边形曲线上点的数量,生成逼近曲线,简化后继操作. 经典的 Doug ...

  5. MTK迁移Oracle单库

    MTK迁移Oracle单库 一. Mtk安装 1.1     安装jdk 要求jdk版本在1.7以上 安装完jdk后将需要的数据库jdbc驱动拷贝到$JAVA_HOME/jre/lib/ext  目录 ...

  6. 《自拍教程22》wget_文件下载工具

    wget用途介绍 日常测试过程中,我们可以用wget命令,来下载一些资源文件. wget是一个很好文件下载命令, Linux操作系统下,自带wget命令. Windows操作系统下,需要自己去下载并配 ...

  7. centos7 字体库。vim乱码

    centos7 字体库.vim乱码 windows上传文件到centos,需要先使用dos2unix命令进行格式转换 先查看/usr/share下有没有这两个文件 没有的话yum -y install ...

  8. VScode搭建OpenCV环境

    用vscode来写opencv代码需要自己编译OpenCV,主要用到MinGW-w64和CMake工具.由于可能存在的版本兼容问题,下载这些工具前最好先访问网站: https://github.com ...

  9. 多字节与Unicode

    编码知识 一.Unicode与多字节(ANSI ) (1)Windows中,Unicode也称为宽字节,多字节也称为窄字节; VS中默认使用Unicode编码,在项目属性>>配置属性> ...

  10. .net core 3.0一个记录request和respose的中间件

    参考资料 https://www.cnblogs.com/wybin6412/p/10944077.html RequestResponseLog.cs using System; using Sys ...